Inline function with multiple arguments and one variable.

6 visualizaciones (últimos 30 días)
Henry  S
Henry S el 16 de Mzo. de 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 comentario
per isakson
per isakson el 16 de Mzo. de 2013
What do you mean by "For each set of (x,y), a,b and c will vary."?

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 16 de Mzo. de 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.

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by