フィルターのクリア

fitting equation with condition on 1 parameter

4 ビュー (過去 30 日間)
aditi
aditi 2014 年 1 月 23 日
コメント済み: aditi 2014 年 1 月 24 日
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 日
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 件のコメント
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 日
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 件のコメント
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 日
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

カテゴリ

Help Center および File ExchangeLeast Squares についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by