lsqcurvefit for function with exp in numerator and denominator
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yagnaseni Roy
le 30 Déc 2015
Commenté : Yagnaseni Roy
le 31 Déc 2015
I've played around with lsqcurvefit to have confidence in my use of it. However the one instance that it doesn't work for me is when my function contains an exponential in both the numerator and denominator. Could someone explain why this is happening and how to fix it?
Example:
Lets's say I know the function I'm looking for is f(v)=exp(3v)/(1+exp(3v))
Now I give MATLAB:
fun=@(x,xdata)=exp(x*xdata)/(1+exp(x*xdata))
xdata=[0.01;0.02;0.03;0.04;0.05]
ydata=[0.507499438;0.514995502;0.522484825;0.529964052;0.537429845]
x0=2;
I expect that by using
x = lsqcurvefit(fun,x0,xdata,ydata)
It should give me x=3. However I get the error:
Function value and YDATA sizes are incommensurate.
It works fine if the function is simply f(v)=exp(3v) though.
0 commentaires
Réponse acceptée
Walter Roberson
le 30 Déc 2015
fun=@(x,xdata)=exp(x*xdata)./(1+exp(x*xdata))
3 commentaires
Matt J
le 30 Déc 2015
Modifié(e) : Matt J
le 30 Déc 2015
Lsqcurvefit is repeatedly making function calls of the form fun(x,xdata), not fun(x,xdata(i)). So, your code for fun() has to know how to handle xdata input in vector form, which is what Walter's change accomplishes.
One thing to be aware of is that xdata and ydata are allowed to be arrays of completely different dimensions. Similarly, there is no assumption in lsqcurvefit that each ydata(i) is a transformation of only one single corresponding xdata(i), like in your example. The only requirement that lsqcurvefit makes of F(x,xdata) is that its output is of the same dimensions as ydata and that it is a differentiable function of x. Accordingly, there is nothing helpful that lsqcurvefit could achieve by calling fun() with one xdata(i) element at a time.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Downloads dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!