# Curve fitting the data series

2 views (last 30 days)
Vijaymahantesh Surkod on 2 Apr 2023
Moved: Walter Roberson on 3 Apr 2023
I am trying to fit the curve to the custom equation in the matlab curve fitting tool, but the tool is way off in its fit as shown in below graph.
I have a resistance variation with frequency of a winding and I want to fit that to a custom equation which is given below. The data of resistance variation with frequency is attached with this message i excel format (where R is resistance and f is frequency).
Rdc + ((R1*(2*3.1416*f*L1)^2)/(R1^2+(2*3.1416*f*L1)^2))
+ ((R2*(2*3.1416*f*L2)^2)/(R2^2+(2*3.1416*f*L2)^2))
+ ((R3*(2*3.1416*f*L3)^2)/(R3^2+(2*3.1416*f*L3)^2))
+ ((R4*(2*3.1416*f*L4)^2)/(R4^2+(2*3.1416*f*L4)^2))
+ ((R5*(2*3.1416*f*L5)^2)/(R2^5+(2*3.1416*f*L5)^2))
Can somebody help with how to go about fitting this equation to the data.

Alex Sha on 3 Apr 2023
Moved: Walter Roberson on 3 Apr 2023
Refer to the results below, should be the unique global solution:
Sum Squared Error (SSE): 0.0378758633912789
Root of Mean Square Error (RMSE): 0.00315213511273881
Correlation Coef. (R): 0.99999990000736
R-Square: 0.999999800014729
Parameter Best Estimate
--------- -------------
l1 6.10390018212527E-7
l2 -2.64028559226925E-7
l3 -1.38720685048637E-6
l4 -1.07429072156079E-5
l5 -0.000108171947535598
r1 4.30598188255995
r2 22.6320483376178
r3 2.80273279207853
r4 2.47713792700109
r5 7.66424573889732
rdc 0.109370435939219

Walter Roberson on 2 Apr 2023
Edited: Walter Roberson on 2 Apr 2023
This takes too long to execute online, but I pasted in the results.
D1 = data(:,1); D2 = data(:,2);
Pi = sym(pi);
syms f L1 L2 L3 L4 L5 R1 R2 R3 R4 R5 Rdc
Y = Rdc + ((R1*(2*Pi*f*L1)^2)/(R1^2+(2*Pi*f*L1)^2)) ...
+ ((R2*(2*Pi*f*L2)^2)/(R2^2+(2*Pi*f*L2)^2)) ...
+ ((R3*(2*Pi*f*L3)^2)/(R3^2+(2*Pi*f*L3)^2)) ...
+ ((R4*(2*Pi*f*L4)^2)/(R4^2+(2*Pi*f*L4)^2)) ...
+ ((R5*(2*Pi*f*L5)^2)/(R2^5+(2*Pi*f*L5)^2));
disp(Y)
residue = sum((subs(Y, f, D1) - D2).^2);
vars = [L1 L2 L3 L4 L5 R1 R2 R3 R4 R5 Rdc];
fun = matlabFunction(residue, 'var', {vars});
[coeffs, res] = fmincon(fun, [1 2 3 4 5 6 7 8 9 10 11]);
disp(coeffs)
Yeqn = vpa(subs(Y, vars, coeffs), 16);
predicted = double(subs(Yeqn, f, D1));
plot(D1, D2, '.', D1, predicted, '-o')
vpa([vars(:) == coeffs(:)],16)
L1 == 32.21771241798128
L2 == 144.1479205169738
L3 == -0.000000935315722798277
L4 == -1.818421517034837
L5 == 214.338332533742
R1 == 26.31801887904511
R2 == 20.64885087528014
R3 == 19.92297810402274
R4 == 47.17697976855884
R5 == -113.1701244234793
Rdc == 23.6692147013051

Torsten on 2 Apr 2023
Edited: Torsten on 2 Apr 2023
The function you define as fitting function tends to Rdc + R1 + R2 + R3 + R4 + R5 as f tends to infinity very fast.
In contrast to this, your R data from test_Rac don't seem to have an asympotic value.
So my guess is that you made a mistake in the specification of your fitting function or the fitting function is not adequate for your data.

### Categories

Find more on Interpolation in Help Center and File Exchange

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!