cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How export functions results to a vector

JPMN
1-Newbie

How export functions results to a vector

Please,

I need export results of functions to a vector or Excel table. I can not work with vectors instead range variables because I have a lot of functions depending of these range variables. After made calculations, I have a function results (with a lot of singularities) and I need find max and min values from these results. I need convert these results to a vector, so, I can use max and min functions to find the maximum and minimum values or export these values to Excel.

Someone have any solutions to this case?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:JPMN)

Now you have posted this very same question three times in different threads - thats annoying and counterproductive. Please avoid doing this in case of future questions.

Attached is something which should help for your understandig, I hope.

View solution in original post

13 REPLIES 13
Fred_Kohlhepp
23-Emerald I
(To:JPMN)

You can give a function a vector just as well as a range variable.

Werner_E
24-Ruby V
(To:JPMN)

Now you have posted this very same question three times in different threads - thats annoying and counterproductive. Please avoid doing this in case of future questions.

Attached is something which should help for your understandig, I hope.

JPMN
1-Newbie
(To:Werner_E)

Werner,

Thank you. Your explanation was perfect.

JPMN
1-Newbie
(To:Werner_E)

Werner,

When the functions have more than 2 variables I can not assembly a matrix to find the max and min values. Can you help me?

Find attached a e.g.

Werner_E
24-Ruby V
(To:JPMN)

When the functions have more than 2 variables I can not assembly a matrix to find the max and min values.

Yes, unfortunately Prime does not support multidomensional arrays.

So as I see it you have two options:

1) Create a different datastructure, e.g. a onedimensional vector (similar to whate the use of range variables would yield). You may use a tricky way with the three range variables or a small programm (preferrable) to do so. I guess a matrix with 4 columns (the three arguments and the function value) and (in your case) approx., 3 millions rows would be a good choice. You would use three nested for loops to do so. The use min() and max()

2) Write a routine (again three nested for loops) which only returns the min and max value (and if you need the three arguments which yield those values) without creating that huge structure.

JPMN
1-Newbie
(To:Werner_E)

Werner,

I found something about assembly a matrix to determine all combinations of four variables in the link http://communities.ptc.com/message/201635#201635 but I can not understand the procedure because the woksheet is very complicated. Please, can you help me to write a programing to assembly the matrix as you suggested in option 1 or create a routine as you suggested in option 2?

Thank you very much for your time and effort.

Werner_E
24-Ruby V
(To:JPMN)

Sorry, I don't see what you have tried and what didn't work. The last two pages are empty. Probably you sent a wrong version of the file as it seems to be the same you sent two days ago.

JPMN
1-Newbie
(To:Werner_E)

Werner,

Please disregard the last two pages, they are really empty. Consider only the page 3/3 of the new file attached. I need find max and min values for the function Fnie03 (B1, H1,D1) and your arguments.

Thank you.

Werner_E
24-Ruby V
(To:JPMN)

Thats the same file posted for the third time, you just deleted the expressions on the right hand side pages.

But I still don't see what you have tried so far to come to a solution and so can't tell where or why it failed. What have you done so far? The link you posted shows how to deal with nested for-loops. Problem in your case can be that you may run out of memory dealing with matrices with some millions of elements.

JPMN
1-Newbie
(To:Werner_E)

Werner,

I did not tried nothing at this moment. I do not know write a routine to find the max and min values or a program to assembly the matrix (three colums with arguments and one column with results). I need your help to give me a e.g. how I can do this.

Thank you for your patience.

RichardJ
19-Tanzanite
(To:JPMN)

How about a different approach. Note that you have discontinuities and more than one maximum, so the guess values matter.

Werner_E
24-Ruby V
(To:JPMN)

OK, just for the completeness sake find attached the brute force way of searching for the maximum using the range variables you provided. I haven't bothered implementing the other method (creating the complete table with all values).

Richard had already posted what seems to be the best solution for your problem - using a solve block.

Some remarks:

  • Your range for b1 seems to be wrong. Given your constraints the range for b1 is from h1 to 2.5*h1. And as h1 is set an upper limit of 3 in, the maximal value for b1 is 7.5in and not 30in as you had chosen as upper limit for b1. Higher values than 7.5in will yield 0 N for Fnie03. I changed the range b1 accordingly.
  • My brute force approach does not find the absolut maximum, it will return b.max=7.375inch instead of the correct 7.5inch. The reason is some kind of numerical round off error. 7.5inch divided by 3inch is calculated being very slightly (~10^-16) greater than 2.5 and so your function Fnie03 returns 0N for b=7.5in and h=3in because one of your constraints is not fulfilled. In every case the brute force approach will only find values within the range variables stepwidth, solutions inbetween are overlooked, which is a main drawback of this method anyway.
  • Richards is right that some guess values will yield a different result, not the absolute maximum (e.g. all values set to 1 in). I am not sure but I guess that if we chose valid guess values which comply to your constraints, we get the correct max every time. That means if h1 is set to 1inch, b1 must be in the range from 1in to 2,5inch and D1 must be a value between 3inch and 10inch. And while different valid guess values may influence the accuracy of the result, I have not yet found a set of valid guess which would not return the correct maximum.
  • I am not sure again but I think the discontinuities Richard mentions should not pose a problem as it seems that they lie outside the valid ranges for the variables. Richad plotted Fnie over h1 with b1=7.5inch and D1=9inch,
    D1=9inch limits h1 to 0.9<=h1<=3, but
    b1=7.5inch limits h1 to 3<=h<=7.5
    So the only valid value for h1 is 3 - the valid part of the graph consists of a single point only.
  • I streamlined your much too long definition for ynie03 using vector/matrix multiplication. Another way would be to split the expression into parts. By this I mean that instead of
    y(x) := a*x^2 + b*x + c/x + d*ln(x) + e*exp(x) + f
    you would type
    part1(x) := a*x^2 + b*x + c/x
    part2(x) := d*ln(x) + e*exp(x) + f
    y(x) := part1(x) + part2(x)
  • I include Richard's approach at the end of my sheet - slightly streamlined using less and clearer constraints. Also I am still using your original function F.nie03 including its if condition.
    06.05.png

It goes without saying that you will have to check all modifications for consistency and correctness.

RichardJ
19-Tanzanite
(To:JPMN)

See my answer here: http://communities.ptc.com/message/241799#241799

Please do not cross post. It is a waste of our time for multiple people to answer your question because they didn't realize it was already answered somewhere else.

Top Tags