Inline function with multiple arguments and one variable.

6 Ansichten (letzte 30 Tage)
Henry  S
Henry S am 16 Mär. 2013
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 Kommentar
per isakson
per isakson am 16 Mär. 2013
What do you mean by "For each set of (x,y), a,b and c will vary."?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

the cyclist
the cyclist am 16 Mär. 2013
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.

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by