# Function for curve fitting

I plotted a graph on Origin software and need to do curve fitting to get accurate results. From my understanding, I need to provide a function for the fitting. So how do I derive the function?

I am actually provided with the function I(x)=I0-I1cos(x-x0) and this function will fit the lowest part of my curve and the program will derive x0 which is the value of x when the y value is the lowest. On the other hand, the function I(x)=I2+I3cos(x-x1) will fit the highest part of the curve and x1 is the value of x when y is the highest.

Can somebody explain those 2 functions and how the software fit the curve with it and how all this can be related to the Taylor's Series?

Dale
Mentor
2020 Award
I cannot help at all with Origin software, but I can help you with the curve fitting in general.

If you can, a priori, separate your data into "high part" data and "low part" data then you could fit the "high part" data to one function and the "low part" to the other function. My guess is that you cannot do that a priori (i.e. without looking at the y values). Therefore you should simultaneously fit all of the data to a single function which would fit both the high part and the low part. The easiest such function would simply be the sum of the two functions.

The other thing that you would like to avoid is any non-linear fitting. Unfortunately, the way that you have it written is non-linear in both x0 and x1.

So, can you think of a simple function which is equal to the sum of the two functions you have given, and pulls all of the fit parameters outside of the sin and cos functions?

• SataSata
Thank you DaleSpam. I don't understand why we need to avoid non-linear fitting but my curve is suppose to look like a period of cos curve. I guess this is a mathematical question but what does those two functions actually mean? Would the result be different if they are change to sin? Why is it minus for the lowest part and plus for the highest part?

Dale
Mentor
2020 Award
I don't understand why we need to avoid non-linear fitting but my curve is suppose to look like a period of cos curve.
There are non-linear fitting routines, but they usually require an initial guess, and they can converge to bad fits sometimes or be very sensitive to the guess or noise in the data. It is not that you cannot do non-linear fitting, but you usually get better results if you can linearize your system (which you can here).

I guess this is a mathematical question but what does those two functions actually mean?
I don't know the context, you haven't said. It means that I(x) has a given relationship to x, but I cannot tell you more.

Would the result be different if they are change to sin?
This is along the lines that you should be thinking about. Since ##\cos(x) = \sin(x+\pi/2)## then if you fit a function to ##\cos(x-x_0)## that is exactly the same as fitting a function to ##\sin(x-k_0)## where ##k_0=x_0+\pi/2##.

Why is it minus for the lowest part and plus for the highest part?
This is the same as with the previous question. There is no difference between fitting ##I_1 \cos(x)## vs ##-I_3 \cos(x)##. They will both fit the same data equally well simply with the fit parameters ##I_1=-I_3##.

• SataSata