MATLAB: Y=sqrt((A^​2*X^2+B^2*​X^2)/(C+D^​2*X^2))

MATLAB

Y=sqrt((A^2*X^2+B^2*X^2)/(C+D^2*X^2))
Hello, In above equation X and Y are obtained from measurement, can we find A B and C which are parameters using measurement data in MATLAB

Best Answer

Hi,
Here are three solutions with lsqcurverfit and non-linear lsqfit.
% Use of LSQCURVEFIT from the optimization toolbox
x = (0:.1:2)'; % You need to plug in your data

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]; % You need to plug in your data
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 %# ok To see the coeff values of A (A & B combined), B (A & B combined), C, D
%% Alternative: NON-Linear-least-squares fit model
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';% Fit model to data.
[fitresult, gof] = fit( x, y, ft, opts );
% Plot fit with data.
figure( 'Name', 'CFTOOL fit: exponential fit 1' );
h = plot( fitresult, x, y);
legend( h, 'y1 vs. x1', 'Sine & Cosine fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel x1; ylabel y1; grid on; shg
fitresult %#ok shows all values of abc1, abc2, abc3, abc4, viz. A, B, C, D
%% An alternative LSQCURVEFIT
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 %#ok to see the coeff. values: A, B, C, D
Good luck.