x = (0:.1:2)';
y =[ 0.0027518, 0.028328, 0.080677, 0.13821, 0.14972, 0.24813, 0.32113 ...
0.36436, 0.35548, 0.4302, .50379, 0.54335, 0.58321, 0.67395, .67685 ...
0.57845, 0.70758, 0.87197 0.80164 0.84333 0.76828];
abcd0=[1 1 1];
RP=@(abcd,x)sqrt(abcd(1)*x.^2./(abcd(2)+abcd(3)*x.^2));
[abcd, error]=lsqcurvefit(RP, abcd0, x, y');
yfit=sqrt(abcd(1)*x.^2./(abcd(2)+abcd(3)*x.^2));
plot(x,y, 'o', x, yfit, '-');
J=sum((yfit-Y').^2); S=sum((Y-mean(Y)).^2); R_sq=1-J/S;
abcd
clearvars
x = (0:.1:2)';
y =[ 0.0027518, 0.028328, 0.080677, 0.13821, 0.14972, 0.24813, 0.32113 ...
0.36436, 0.35548, 0.4302, .50379, 0.54335, 0.58321, 0.67395, .67685 ...
0.57845, 0.70758, 0.87197 0.80164 0.84333 0.76828]';
ft = fittype( 'sqrt((abc1*x^2+abc2*x^2)/(abc3+abc4*x^2))', 'coeff', {'abc1', 'abc2', 'abc3', 'abc4'} );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
[fitresult, gof] = fit( x, y, ft, opts );
figure( 'Name', 'CFTOOL fit: exponential fit 1' );
h = plot( fitresult, x, y);
legend( h, 'y1 vs. x1', 'Sine & Cosine fit 1', 'Location', 'NorthEast' );
xlabel x1; ylabel y1; grid on; shg
fitresult
x = (0:.1:2)';
y =[ 0.0027518, 0.028328, 0.080677, 0.13821, 0.14972, 0.24813, 0.32113 ...
0.36436, 0.35548, 0.4302, .50379, 0.54335, 0.58321, 0.67395, .67685 ...
0.57845, 0.70758, 0.87197 0.80164 0.84333 0.76828];
abcd0=[1 1 1 1];
RP=@(abcd,x)sqrt((abcd(1)*x.^2+abcd(2)*x.^2)./(abcd(3)+abcd(4)*x.^2));
[abcd, error]=lsqcurvefit(RP, abcd0, x, y');
yfit=sqrt((abcd(1)*x.^2+abcd(2)*x.^2)./(abcd(3)+abcd(4)*x.^2));
plot(x,y, 'o', x, yfit, '-');
J=sum((yfit-y').^2); S=sum((y-mean(y)).^2); R_sq=1-J/S;
abcd
Best Answer