fitting equation with condition on 1 parameter

I have to fit an equation over my data. Equation has two unknows parameters to be found i.e a and b...but if i deliberately want that the b value should lie betweem 0.2 and 2 and then find 'a' and 'b'...how can i do that???

 채택된 답변

Matt J
Matt J 2014년 1월 23일
편집: Matt J 2014년 1월 23일

0 개 추천

Here is a simple script for fitting a Gaussian f(z) = a*exp(-b*z^2) using LSQCURVEFIT subject to bounds a>=0, 0<=b<=7. You should run it, study it, and adapt it to your needs.
f=@(p,z) p(1)*exp(-p(2)*z.^2);
x=linspace(0,2,10);
y=f([1,2],x)+rand(size(x))/10; %simulated data
p=lsqcurvefit( f, [.5,.5], x,y, [0,0],[inf,7]); %perform fit
plot(x,y,'*', x, f(p,x)) ;
You should also, of course, read "doc lsqcurvefit" to understand the input syntax and know what additional options you have.

댓글 수: 7

aditi
aditi 2014년 1월 23일
thanks matt...
but could u please explain the equation :
p=lsqcurvefit( f, [.5,.5], x,y, [0,0],[inf,7]);
what is [.5,.5] and if i dont want to give any condition for a???
Matt J
Matt J 2014년 1월 23일
편집: Matt J 2014년 1월 23일
[.5,.5] is my initial guess of the parameters. You should see an explanation of that in "doc lsqcurvefit".
Bounds on individual parameters can be set to inf and -inf if you effectively want them unconstrained. You can see in my example that I set upper and lower bounds on a of 0 and inf, meaning that a is not bounded from above, but is constrained to be >=0.
aditi
aditi 2014년 1월 24일
hey matt... oh okay....i tried this...n found almost d correct results...i will try for other data sets...thanks a lot
but 1 thing...when we plot its showing discontinous curve...how to smoothen it...i mean like in cfools we get the smooth fit curve...similarly how to do here???
Matt J
Matt J 2014년 1월 24일
The curve isn't discontinuous. You're just not plotting it at very many points.
aditi
aditi 2014년 1월 24일
ha right...i meant that only... so how to smoothen it...??
Matt J
Matt J 2014년 1월 24일
Plot at more densely spaced points.
aditi
aditi 2014년 1월 24일
I have only 5 data points...for x and y...so how to plot both the data points and fit curve both(the smoothed one) on the same plot...

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Amit
Amit 2014년 1월 23일

0 개 추천

You can use fmincon.
I would think that these a and b are from you previous post, where fminsearch were used. fmincon is similar to fminsearch but support bounds. More details on fmincon is here http://www.mathworks.com/help/optim/ug/fmincon.html

댓글 수: 4

aditi
aditi 2014년 1월 23일
hey amit...yes...the same question... could you plz explain it according to my problem plz...as u know the problem completely ...
Matt J
Matt J 2014년 1월 23일
편집: Matt J 2014년 1월 23일
lsqnonlin or lsqcurvefit would be better, if the only constraints are bounds.
Amit
Amit 2014년 1월 23일
Actually MAtt's idea is better.
aditi
aditi 2014년 1월 23일
Matt could you please explain how to use it...

댓글을 달려면 로그인하십시오.

Alan Weiss
Alan Weiss 2014년 1월 23일
편집: Alan Weiss 2014년 1월 23일

0 개 추천

There are some documentation examples that show how to fit equations. Adding bound constraints is easy for lsqnonlin or lsqcurvefit.
Hope this helps,
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

질문:

2014년 1월 23일

댓글:

2014년 1월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by