fitting a curve using a complex equation as shown
Show older comments
Hi,
I am trying to fit a curve using this function by lsqnonlin.

But am not able to find a reliable fit using the code as shown below. Can anyone tell me how could i get a better fit.
Matlab Code
%%Function file
function F = f(c,w,stiff)
errors=c(1)+(c(2)*w.^2*c(4)^2./(1+w.^2*c(4)^2)+c(3)*w.^2*c(5)^2./(1+w.^2*c(5)^2))+1i*(c(2)*w*c(4)./(1+w.^2*c(4)^2)+c(3)*w*c(4)./(1+w.^2*c(5)^2))-stiff;
F = [real(errors(:)); imag(errors(:))];
%% Main program code
clc
clear all
format long
w=[1.02E+00,1.92E+00,2.94E+00,3.96E+00,4.98E+00,6.00E+00,7.01E+00,7.92E+00,8.94E+00,9.95E+00,1.10E+01,1.20E+01,1.30E+01,1.40E+01,1.49E+01,1.60E+01,1.70E+01,1.80E+01,1.90E+01,2.00E+01,2.10E+01,2.19E+01,2.30E+01,2.40E+01,2.50E+01,3.00E+01,3.50E+01,3.99E+01,4.50E+01,5.00E+01]';
stiff =[8.92E+02,9.12E+02,9.28E+02,9.37E+02,9.43E+02,9.50E+02,9.55E+02,9.59E+02,9.64E+02,9.68E+02,9.72E+02,9.74E+02,9.74E+02,9.78E+02,9.81E+02,9.83E+02,9.84E+02,9.87E+02,9.89E+02,9.91E+02,9.92E+02,9.94E+02,9.95E+02,9.94E+02,9.94E+02,1.00E+03,1.01E+03,1.01E+03,1.01E+03,1.02E+03]';
plot(w,stiff,'b*')
hold on
x0=[0 0 0 0 0]; % Arbitary inital guess
[x,resnorm] = lsqnonlin(@(c)f(c,w,stiff),x0);
c(1)=x(1);
c(2)=x(2);
c(3)=x(3);
c(4)=x(4);
c(5)=x(5);
z=c(1)+(c(2)*w.^2*c(4)^2./(1+w.^2*c(4)^2)+c(3)*w.^2*c(5)^2./(1+w.^2*c(5)^2))+1i*(c(2)*w*c(4)./(1+w.^2*c(4)^2)+c(3)*w*c(4)./(1+w.^2*c(5)^2));
z1=abs(z);
plot(w,z1,'r')
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

