Is it possible to pass fitting coefficients as arguments?
1 view (last 30 days)
Show older comments
Hello everyone,
I'm trying to perform a nonlinear fit via three parameters. However, I have to pass one of the parameters to an external function. Is it possible to do it? How?
Here is the part of my code where I try to do what I explained before.
zeqn = @(coefs, y) coefs(1)+lh+y./coefs(2) + invfwlc((y*coefs(3))/kT);
InitGuess = [100 0.01 10]
fSSR = @(coefs, z, y) sum(( z - zeqn(coefs, y) ).^2);
[MyCoefs, Sr] = fminsearch(@(MyCoefsDummy) fSSR(MyCoefsDummy,z,y),InitGuess,optimset('Display','iter','MaxFunEvals', 50000,'MaxIter',1000,'TolFun',1.e-8,'TolX',1.e-8));
"invfwlc" is the external function I want to evaluate.
Thank you in advanced.
1 Comment
Star Strider
on 21 Feb 2014
Edited: Star Strider
on 21 Feb 2014
Once you identify the parameters, passing one shouldn’t be a problem. What have you already tried? Are you having problems with it? Does it give you the answers you expect?
I had to make up values for y, z, lh, and kT, and an expression for invfwlc but with those additions, the code you posted ran without problems.
-------------------------------------------------------------------
Added ahead of posted code:
z = 7; y = 3; lh = 13; kT = 273*1.38E-023; % Necessary to run code
invfwlc = @(x) exp(-x); % Necessary to run code
Answers (1)
Alvaro
on 24 Feb 2014
1 Comment
Star Strider
on 25 Feb 2014
Edited: Star Strider
on 25 Feb 2014
I’ve been working on this, but I cannot reproduce the error.
Please post the line (or lines) throwing the error. It is obvious that l is a scalar.
Is y a vector?
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!