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
Hi there!
I want to get one value interpolated from the parameter, obtained from the calculation routine.
The goal is to perform interpolation of the curvature value Curvature (Alef, the second output's result) as a function of the bending moment value (Moment, the first output's result) from the given value of M_fact.
By using the "linterp" function, I got stuck with the error message:
"The elements in this vector must be in ascending order".
After reviewing the relevant topic on the PTC forum, the only possible solution was to start the list of matrices at 1, yet my attempt to set ORIGIN:=1 hadn't worked.
I use the Prime 10.0.0 version of the software.
The file with the problem is attached.
I'd be very appreciative of any assistance and advice regarding the issue.
Solved! Go to Solution.
c in Alan's approach is the vector index.
His functions starts at this index and increases it until appropriate x-interval (in your case moment values) is found.
When we use 0 as last function argument, the function starts at index 0 and goes up until it detects the the value 248 kJ lies somwhere between value index 18 and value index 19 and then interpolates. That way the first solution is found.
When start index c=19 is used the function runs up until it detects that 248 lies between value #49 and #50 and interpolates and so finds the second solution.
Of course it may happen that no suitable interval is found.
As an example you may look for moment=150 kJ
This value (150 kJ) lies between value index #8 and #9 and there is no second solution afterwards.
So if you use start index 9 or higher, no solution can be found and the function throws an error because it tries to access a value beyond the last vector element.
You may modify Alan's function so that it returns a NaN if no value was found:
The situation is similar as in my approach above: If you always use start index c=0 you will always get a solution (if it exists) but in case more than one solution exists, you will just get the first one,
In my approach the same applies if you always use the same guess value, say 0.
It is your responsibility to realize whether there are multiple solutions and to choose the index or guess value so that you also get the other solutions. A plot can help to see if there could be a second solution and where approximately it may be.
It may be easier to find a suitable guess value for the second solution than to find a suitable start index. But then I also may be wrong about that...
Hi,
I am not expert, therefore I only wanted to check whether Moment values form an increasing sequence.
The above picture tells me that values are growing up to Moment31 ... this can be seen in the graph, too.
I extracted growing part of Moment and corresponding part of Curvature and >>> lininterp works
i@MartinHanak Thank you for your explanation. As far as I understand, MATHCAD's linterp function gets stuck when both ascending and descending orders are present simultaneously.
Am I right?
Suppose I change the input data for concrete grade, reinforcement area, and so on, which will be reflected in the other "stress-strain" curve forms. Thus, I'd have to deliberately restrict my MATHCAD output to only ascending or only descending order???
If this is true, I cannot rely on automatic interpolation from the range using the built-in MATHCAD function...
@Ivan_Pat wrote:
i@MartinHanak Thank you for your explanation. As far as I understand, MATHCAD's linterp function gets stuck when both ascending and descending orders are present simultaneously.
Am I right?
Suppose I change the input data for concrete grade, reinforcement area, and so on, which will be reflected in the other "stress-strain" curve forms. Thus, I'd have to deliberately restrict my MATHCAD output to only ascending or only descending order???
If this is true, I cannot rely on automatic interpolation from the range using the built-in MATHCAD function...
Hi,
please be patient and wait until more experienced user responds.
"linterp" requires the vector of abscissa value ("x-values") to be in strictly ascending order. That's the reason your attempt fails.
Reason for this requirement is that a function (which "linterp"basically is) must be unique. For one single argument there should be just one single result.
In your example the input value 248 kJ would have two(!) different possible results for curvature - approx. 5.7 km-1 and also 17.8 km-1.
One possible way to deal with this task is to turn it the other way round. Fortunately your curvature values are in strictly ascending order. So we can create a function for the moment depending on the curvature using linear interpolation.
Then we can create a function for the inverse (moment -> curvature) by using the "root" function (a solve block with find also could be used). I made it a function(!) in two arguments - the first is the moment and the second is a guess value for the curvature. Depending on the guess you provide you may get the one or the other solution in case more than one solution exists.
BTW, its not necessary to make the values unit-less and using "augment" with just one vector as argument does not have any effect at all and could be omitted.
Prime 10 sheet attached
@Werner_E Thank you so much for the possible way to solve the issue.
It seems like each time I have to intervene manually in the calculation to determine the interpolated value...
@Ivan_Pat wrote:
@Werner_E Thank you so much for the possible way to solve the issue.
It seems like each time I have to intervene manually in the calculation to determine the interpolated value...
No, you can use the same guess value every time.
But in case where more than one solution exists (like with 248 MPa and you sample data) you have to find a way to decide which value you want to see. Thats the reason I had not implemented a fixed guess value but used a second function argument to provide a guess value.
As a possible alternative to the other suggestions here, you could use a "home-grown" variant of linterp that doesn't require strictly monotonic variation of the independent variable.
@AlanStevens Thanks a lot!
I guess that your "home-grown" function serves as an exact interpolation function, as it should.
The only question that arose: what does the "c" character stand for?
As I may be misunderstanding, is this the index of the matrix element, in our case, of the Moment? Or is it the guessed value as in @Werner_E explanation ("...the second is a guess value for the curvature.")?
I indeed want to understand this stuff.
c in Alan's approach is the vector index.
His functions starts at this index and increases it until appropriate x-interval (in your case moment values) is found.
When we use 0 as last function argument, the function starts at index 0 and goes up until it detects the the value 248 kJ lies somwhere between value index 18 and value index 19 and then interpolates. That way the first solution is found.
When start index c=19 is used the function runs up until it detects that 248 lies between value #49 and #50 and interpolates and so finds the second solution.
Of course it may happen that no suitable interval is found.
As an example you may look for moment=150 kJ
This value (150 kJ) lies between value index #8 and #9 and there is no second solution afterwards.
So if you use start index 9 or higher, no solution can be found and the function throws an error because it tries to access a value beyond the last vector element.
You may modify Alan's function so that it returns a NaN if no value was found:
The situation is similar as in my approach above: If you always use start index c=0 you will always get a solution (if it exists) but in case more than one solution exists, you will just get the first one,
In my approach the same applies if you always use the same guess value, say 0.
It is your responsibility to realize whether there are multiple solutions and to choose the index or guess value so that you also get the other solutions. A plot can help to see if there could be a second solution and where approximately it may be.
It may be easier to find a suitable guess value for the second solution than to find a suitable start index. But then I also may be wrong about that...
Thank you so much for the explanation on how it works.
I really don't have such a programming background for correctly interpreting your's and @AlanStevens ideas, proposed for my issue.
But I'll study them to make my routine more polished))
I don't know how you would deal with more than one solutions - if you need both, or just the smallest of the two or the largest?
Here is a function which returns all possible solutions in one go. You don't have to provide a guess value or a start index as the function always runs through the whole data set and looks for suitable values. This is similar to Alan's approach with c=0 but without stopping at the first solution found. As I am able to use the full Prime version I can use a for loop instead of the recursive approach used by Alan.
Unlike the built-in "linterp" this "Linterp" function does not extrapolate.
If the result is unique than this value is returned. If there are more solutions they are returned as a vector. And if no solution is found a NaN is returned.
Depending on your needs it may be considered more consistent if the result is always a vector/matrix - even if there is just one solution. To achieve this you simply replace the last line by "R"
And if the "NaN" in the "no solution" case should be a 1x1 matrix as well you could use
And if you wan the function to just return the largest of all solutions found you could use
Here a list of possible last lines and their effect
So you have to decide which is the best way for you to handle the cases "more than one solution found" and "no solution found".
Prime 10 sheet attached
I'm really impressed by your comprehensive explanation of the logic and how it works.
I can only guess that you have a bold programming background and are pretty familiar with coding nuances.
Thanks a lot for your patience and assistance.🙏
I appreciate it a lot.
Cheers
