Calibrating a non-linear array in MATLAB using 2 variables
显示 更早的评论
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?
回答(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 个评论
Iliya Nemtsov
2017-7-11
Matt J
2017-7-12
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).
类别
在 帮助中心 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!