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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Fit function to plotted graph (that resembles the shape of a haft circle)

ksk_10594232
9-Granite

Fit function to plotted graph (that resembles the shape of a haft circle)

Hi

I have plotted the results from two vectors. The graph resembles the shape of a half circle and I would like to find a function that fits the data so intersection points can be determined for other functions. 

I have tried many different curve-fitting tools but can't find a proper one that works. 

 

I'm  thankful for any help!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I get slightly different values using CurveExpert Pro

Werner_E_0-1676906036862.png

And I get similar values in Prime using genfit() (though genfit is VERY sensible wrt the guess values).

Werner_E_1-1676906149759.png

BTW, as we can see far to the right of the Prime sheet how the data is actually calculated it should not surprise that a sinusoidal fit is suggested by CurveExpert 😉

 

View solution in original post

17 REPLIES 17

If I digitize the data, then rotate it so X is a function of Y, and send it to CurveExpert,, I get

Fred_Kohlhepp_0-1676896848850.png

Which has the form

Fred_Kohlhepp_1-1676896917526.png

Prime 4 attached

 

 

I get slightly different values using CurveExpert Pro

Werner_E_0-1676906036862.png

And I get similar values in Prime using genfit() (though genfit is VERY sensible wrt the guess values).

Werner_E_1-1676906149759.png

BTW, as we can see far to the right of the Prime sheet how the data is actually calculated it should not surprise that a sinusoidal fit is suggested by CurveExpert 😉

 

Wow! Thanks for the good explanation! 

Its probably better to use the fitted cosine function itself like Fred had shown instead of the splitted arcus cosine used by me.

You may also add units to your fitting function.

Its also possible to use genfit() with units, but when I tried it showed to be extremely sensible with respect to the guesses, so I think its better to use it unit-less and add the units afterwards as shown below and in the attached sheet.

Werner_E_1-1676971496867.png

 

BTW, why did you "hide" the calculations so far to the right instead of using a collapsed area? See attached sheet.

 

Worksheet in P6 format included

 

Thank you Werner_E, Very appreciated!

 

Is it possible to get a Y-function as a function of X instead of the above suggestion? That would really facilitate my further calculations.

 

Thanks in advance


@ksk_10594232 wrote:

Thank you Werner_E, Very appreciated!

 

Is it possible to get a Y-function as a function of X instead of the above suggestion?


???? I had shown exactly that in my first reply!

As in the area of interest for every value of x there are TWO different values for y, it can't be a function because a function has to be unique by definition.

But it was possible to split into two functions - one for the upper and another for the lower part.

Because x=f(y) is a cosine (you may turn it into a sine by shifting for a quarter of the period if you like), the aforementioned functions for the upper and lower part basically are arccos() functions. If you look at my first reply you may notice that the only difference is a sign in front of the acos() function.

I considered splitting into two function not to be very elegant and so picked up Freds approach of using y as the independent variable.

So if you need to calculate BOTH N-values corresponding to a given M-value, you will have to use BOTH function shown in my first reply (I called them f.fit1() and f.fit2() in that post).

Thank you.

 

I'm aware of that, but your first solution only yields the upper or the lower part of the function (as a function of x). I'm seeking for a function that fits the plot in the first quadrant, i.e. the intersection of the x-axis as well. 

 

The reason I want to find a continious function that fits the two vectors is to be able to determine intersection points for other functions. I guess the Solve block does not work properly for non-continious graphs?

 

 

Even if you restrict the calculation to the first quadrant, there is an area at the right end, where you have TWO N-values (y) for a given M-value (x). So there can't be one single function N(M) (or y(x)).
For M=22.3 kNm you get two different values for M (approx. 123.6 kN and 13.0 kN)

You can see this clearly when you zoom in at this position. What you also can see that way is, that the fit of course is not perfect. After all its an approximation and not an interpolation.

Werner_E_1-1677072022011.png

 

Its not clear to me what the final goal would be. There sure can't be no continuos function y(x) because of the aforementioned ambiguity.

To intersect with other curves you could as well use the continuous function x(y).

Depending on your needs a (continuous and unique) parameter representation might also do the job.

Werner_E_2-1677072459381.png

Of course this is just y(x) spitted into the components.

 

 

The ultimate goal is to find the point of intersection between two graphs plotted from x- and y-vectors, and apply the solve block function so the intersection can be determined smoothly. I have tested this before but I get inaccurate roots due to, what I believe, is because of non-continous plots? That's why I want to find a function that fits each plotted graph, and apply the solve block function accordingly. 

 

Hope you understand what I'm looking for.   

You would have to give a concrete example of which graphs you would like to intersect.

As already written, there is no single function y(x) or N(M) because of the mentioned ambiguity, so you would have to find another way to get what you are looking for.

 

I thought so far that your question would be of more theoretical nature about how a fit  function could be found given a couple of measured values and that instead of providing a bunch of actual measured values you provided calculated values which were derived by (somewhat hidden) calculations. So for these values a fit would not be necessary at all as you know the functions they stem from.
So I thought you wanted to learn how to get a fit function an would later apply to real world measured data instead of calculated values.

 

From what you wrote at last I guess that you actually only have calculated vectors and try to find common values!? There might be a simpler way to achieve this, maybe by some sort of linear interpolation instead of an approximated fit function, but I am not sure.

If the vectors are created by combining two vector calculated by different formulas, you might also use the formulas themselves instead of the calculated values and try the intersection with each part separately.

 

I will return to you with a concrete example, it makes it all easier. It takes a little time to clean the file from all irrelevant information.

 

Would you mind attach the file for the first solution please?

 

 

Sorry, that file does not exist anymore.

But the values a,b,c, and d are the same and derived the same way as in my posted sheet (its not necessary to combine the values in a vector XY and sort them as I did in the first post) and all you have to retype are the definitions of the functions f.fit() and f.fit2() as shown in the picture.

Actually these two function definitions were combined in my function g(x) posted in my last sheet, which returns both values in a vector.

See attached file. I hope my query is clearer this time 🙂

Hope that the attached sheet is of help.

I used linear interpolation, but the same method also could be applied to fitted functions derived by using gefit() or the like.

Your data vectors are not measured data but data derived by calculations.  Your calculations worked with vectors of input values from the start. So it might also be possible to turn the calculations into functions of the input values and use these to find the desired point of intersection. Had not given this approach (maybe the most natural one) much thought, though, as I would mean larger changes in your worksheet. So I just worked from the two pairs of calculated vectors and used linear interpolation to turn them into functions.

Werner_E_0-1677156172087.png

Remark: The second plot is still turned into a function x2(y) for the aforementioned reasons. But if you limit the curve to x-values from 0 to about 20, because you know/see that the looked for point is somewhere in this range, you can also turn this part into a "normal" function y2(x) and then solve the equation y1(x)=y2(x).

 

Thank you so much! That really helped me. 

It is possible to define functions rather than vectors for your plots:

Fred_Kohlhepp_0-1677257723199.png

I've done it in the attached Prime 8 Express sheet.

Attempts to solve for the intersection (in Express) have failed; maybe someone with a solve block capability?

Note that it's possible to create functions only using the parameter "y", which would result in a single intersection point.  I introduced a second variable (l_k) hoping to be able to trace the intersection point as a function of that variable.

Fred_Kohlhepp_1-1677258248309.png 

If only one point is required . . .

 

Good Luck!

 

Here you are ...

As solve block does the job pretty well but is a bit  sensitive wrt the guess values

Werner_E_1-1677270927150.png

 

 

Top Tags