Skip to main content
11-Garnet
August 17, 2023
Solved

Curve fitting

  • August 17, 2023
  • 7 replies
  • 13959 views

Dear experts,

I have a question about curve fitting by using Mathcad.

I have a formula call Steinmetz's equation.

Jason_power_0-1692281985281.png

 

if I have a data like below figure.

Based on the Steinmetz's equation, I want to solve the "a" ,"b" and "k" from each frequency.

how do I use Mathcad to do the curve fitting.

Could you please give me some example.

 

 

Jason_power_3-1692282260929.png

 

 

 

 

 

Best answer by Werner_E

Here is an attempt to calculate just one set of parameters (a,b,k) which should fit all five curves.

The solve block used is not very sensible with respect to the guess values.

Werner_E_0-1692611035105.png

As you can see in the following plots, the fit isn't equally good for all curves. Of course you get better fits if you derive the parameters for each curve separately.

Werner_E_1-1692611134123.png

 

Attached sheet is in format Prime 6

 

7 replies

25-Diamond I
August 17, 2023

Looking up the information in he help about the function genfit() should help you.

J_power11-GarnetAuthor
11-Garnet
August 19, 2023

Got it.

24-Ruby III
August 17, 2023
J_power11-GarnetAuthor
11-Garnet
August 19, 2023

thanks.

ttokoro
21-Topaz I
21-Topaz I
August 18, 2023

Please share your Mathcad sheet that has your plot data set.

t.t.
J_power11-GarnetAuthor
11-Garnet
August 19, 2023

I know how to do it, thanks.

21-Topaz II
August 18, 2023

Hi,

Part of the input for the 'genfit()' function are two column vectors vx and vy being the data you intend fitting to.

So my question is do you have the original data that forms the graph or are you working only on an image of the graph?

If you only have the graph you will need a program like PlotDigitize to get some x,y values.  That is what I have done here.

Capture.JPG

J_power11-GarnetAuthor
11-Garnet
August 19, 2023

@terryhendicott 

 

I have original data. 

Thanks for your advice. I know how to do.

by the way, I have other question.

if I have 5 curve in one plot. 

could I use genfit to find the coefficient?

for example, 

in your plot, you only draw 1150Hz curve in Mathcad and you use genfit to find the coefficient.

can I draw the all frequency to find the coefficient?

 

21-Topaz II
August 20, 2023

Hi,

You need to use genfit() five times to get the coefficients.  One for each line on the curve.

If the data was organised with vx being a matrix with each column being the B data for one line and vy being a matrix with each column being the data for one line in turn, you can use one genfit solution.  This would generate a nested matrix of k, a, b solutions.

Capture.JPG

Cheers

19-Tanzanite
August 18, 2023

From where did you get that graph: Loss vs B (from which book/site/article/etc)? Do you only have the picture or also the data points?

J_power11-GarnetAuthor
11-Garnet
August 19, 2023

@Cornel  
I have data point in my side.

 

23-Emerald I
August 20, 2023

Express does not have access to "genfit."  But, by taking the logarithm of the equation we can turn it into something that least squares can deal with.  Attached is a sample in version 4.

 

Note that only one curve's data was used to develop the solution.  If the constants (k, a, b) are true physical parameters then the curves for other frequencies should also be correct.

21-Topaz II
August 20, 2023

Hi,

By the way Fred how did you get the red area line?

 

Fred's log techniue

Capture.JPG

genfit with start guess of 1,1,1. You can get a different k,a,b by changing the guess values

Capture2.JPG

So there are many solutions for k,a,b on the one curve. meaning it may be possible for one set of k,a,b for all curves

 

Please upload you data

J_power11-GarnetAuthor
11-Garnet
August 20, 2023

Hi @terryhendicott ,

 

Sorry too late to upload the data.

please see the attached file.

I have five curve with different frequency in Excel file.

but I still can only find the solution case by case, 

Werner_E25-Diamond IAnswer
25-Diamond I
August 21, 2023

Here is an attempt to calculate just one set of parameters (a,b,k) which should fit all five curves.

The solve block used is not very sensible with respect to the guess values.

Werner_E_0-1692611035105.png

As you can see in the following plots, the fit isn't equally good for all curves. Of course you get better fits if you derive the parameters for each curve separately.

Werner_E_1-1692611134123.png

 

Attached sheet is in format Prime 6

 

25-Diamond I
August 21, 2023

As the the fit for frequencies 100 KHz and 300 kHz is worst, you can "weight" the conditions for these frequencies by multiplying the difference by a larger value so that they are are considered more than the others. The fit is now better for these two frequencies but much worse for the others, especially 400KHz and 500 kHz.

Werner_E_2-1692612385499.png

You may play around with different "weights" but the best overall fit (apart from fitting each curve separately) seems to be provided with equal weight for all as in my initial posting.

 

 

25-Diamond I
August 23, 2023

Fred first suggested to take the logarithm of the equation and do the fit then. Also ttokoro showed the result of this approach.

You must keep in mind the the results are not the same as when doing the fit with the original, unlogarithmized data.

Taking the log and then doing a least squared errors fit weights the errors for larger values less (because the fitting algorithm is using the absolute value of the  errors and due to the log they are now smaller). This may not matter or even may be desired but it also may be not appropriate. It depends and its up to you to decide if you want this to be done or not.

I have added the log-fit to my sheet and you may compare (the log fit is the one with the functions P2

Werner_E_0-1692808788149.png

Werner_E_1-1692808801895.png

The differences are not huge, but noticeable, especially for the lower frequencies 100kHz and 200 kHz which use higher values of B.

The differences can also be observed in a log-log-plot where we have linear functions

Werner_E_2-1692808999873.png

 

Modified sheet in Prime 6 format attached