Inline function with multiple arguments and one variable.

조회 수: 6 (최근 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 CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by