Inline function with multiple arguments and one variable.

6 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

the cyclist
the cyclist il 16 Mar 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.

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by