Fitting an equation with x,y variables and b, d constant.

Hi,
I have an equation.
x=[10,50,100,300,500,1000,1500,2000,3000];
y=[0.11,0.17,0.2,0.24,0.29,0.3,0.31,0.35,0.38];
I want to fit this equation and get b and d values.
I tried with lsqcurvefit command, but I can not convert this equation to y=function(x).
Anybody has a suggestion.

 Accepted Answer

Use lsqnonlin and define the functions f_i as
f_i = 1/a*(b-ydata(i)).^1.5-log(d./xdata(i))+0.5*log(1-ydata(i)/b)
Best wishes
Torsten.

5 Comments

And how to define b, d constant values in f_i by fitting?
Could you give some details more clearly?
Best,
You don't define them - they are solved for by lsqnonlin:
x=[10,50,100,300,500,1000,1500,2000,3000];
y=[0.11,0.17,0.2,0.24,0.29,0.3,0.31,0.35,0.38];
a=...;
fun = @(p) 1/a*(p(1)-y).^1.5-log(p(2)./x)+0.5*log(1-y/p(1));
p0=[1 1];
p = lsqnonlin(fun,p0)
Best wishes
Torsten.
Ok, I got it.
How to get Chi-Square from lsqnonlin command?
lsqnonlin does not calculate Chi-Square or any other probability measure. It does not create any hypotheses about how well the model fits: it only searches for a minimum.
You don't get statistics from lsqnonlin.
You will have to use tools like nlinfit in combination with nlparci and nlpredci.
Best wishes
Torsten.

Sign in to comment.

More Answers (1)

a = some value
y1 = @(b, d, x) -b .* (exp(-(2/3) .* lambertw(-3 .* (b.^3 ./ a.^2).^(1/2) .* d.^3 ./ x.^3)) .* d.^2 - x.^2) ./ x.^2
y2 = @(b, d, x) -b .* (exp(-(2/3) .* lambertw(3 .* (b.^3 ./ a.^2).^(1/2) .* d.^3 ./ x.^3)) .* d.^2 - x.^2) ./ x.^2;
guessbd = rand(1,2);
fit1 = fittype(y1, 'coefficients', {'b', 'd'}, 'dependent', 'y', 'independent', x);
fit2 = fittype(y2, 'coefficients', {'b', 'd'}, 'dependent', 'y', 'independent', x);
[bd1, gof1] = fit( x, y, fit1, 'startpoint', guessbd );
[bd2, gof2] = fit( x, y, fit2, 'startpoint', guessbd );
The pair of fits is due to there being two solutions when y is expressed in terms of x, almost identical but differing in sign of the LambertW expression. You would need to check the goodness of fit results to see which was better.

1 Comment

Ok, I got it.
How to get Chi-Square from lsqnonlin command?

Sign in to comment.

Categories

Asked:

ly
on 17 Nov 2016

Commented:

on 21 Nov 2016

Community Treasure Hunt

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

Start Hunting!