Calibrating a non-linear array in MATLAB using 2 variables
Show older comments
Hello, Currently, I am trying to optimize the following equation:
function fcpred = bup(x)
load calset
c1 = x(1);
c2 = x(2);
fcpred = 100./(1+exp(((c1.*(-2*cprime))+(c2.*cprime.*ln100d))));
end
And claset contains obs, ln100d and cprime 44*1 arrays. Subjected to the contraint:
obs - fcpred = 0
and wish to minimize COV of the above. I have tried:
[x,fval] = fmincon(@bup,[0 0],[],[],[],[],[],[],@opt)
Where [opt]:
function [c, ceq]=opt(x)
load calset_LC
ceq = obs - fcpred
c = []
end
But to the error requesting that the supplied function should return a scalar value. Have I used the wrong function? or should I look to solve it as a system instead?
Answers (1)
I have the impression that like you are trying to solve
100./(1+exp(((c1.*(-2*cprime))+(c2.*cprime.*ln100d)))) - obs = 0;
If so, and if c1 and c2 are unconstrained, you would probably want to use fsolve,
[x,fval] = fsolve(@(x) bup(x) - obs, x0 )
The initial guess x0 can probably be obtained by rearranging this as a linear equation
log(100./obs-1) = c1.*(-2*cprime) + c2.*cprime.*ln100d
and solving. Or, maybe the linear solution is already good enough for your purposes.
2 Comments
Iliya Nemtsov
on 11 Jul 2017
Matt J
on 12 Jul 2017
Thank you for your suggestion but I am trying to eliminate the residual of the result, hence: obs - fcpred = 0
I don't see how you can do that. You have 44 residuals to drive to zero, but only 2 degrees of freedom (c1 and c2).
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!