Inline function with multiple arguments and one variable.

3 ビュー (過去 30 日間)
Henry  S
Henry S 2013 年 3 月 16 日
Hi, I have several hundreds set of (x,y) which I want to fit with a known function with three constant factors (will be varied with (x,y)). I already realized it with one set of (x,y). However, I want to do a for loop to get the three constant factors for each set of (x,y). I was thinking to make each factor into a array. How should I do that?
Say two sets of (x,y): x1=[1,2,3,4,5]; y1=[4,3,5,6,7];
x2=[1,2,3,4,5]; y2=[3,5,6,7,10];
The function is y=a*log(b*x)+c. For each set of (x,y), a,b and c will vary.
Thanks,
Henry
  1 件のコメント
per isakson
per isakson 2013 年 3 月 16 日
What do you mean by "For each set of (x,y), a,b and c will vary."?

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2013 年 3 月 16 日
Notice that because log(bx) = log(b)+log(x), you can simplify your fit to one of the form
y = a*log(x) + d
where d = a*log(b) + c. Then, if you define z = log(x), then you get
y = a*z + d
which is very simple to deal with. You could fit an nth-degree polynomial to that with
P = polyfit(z,y,n)
or do a linear regression with
beta = regress(y,z)
from the Statistics Toolbox.
You can actually do your entire set at once if you use the mvregress() function, but the syntax for that command is a little tricky if you don't know about design matrices.

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by