fsolve

9 次查看(过去 30 天)
Doug Hates Squirrels
I'm working on solving for the values of a series of parameters that are from a set of equations. While I have tried following every example I can find for fsolve, none have been particularly helpful. I've past the code from my m file below. Any help is appreciated. THANKS!
function F=calibrate(X)
%known variables;
nm = 0.031;
se = 0.108;
ne = 0.862;
c = 0.091;
ke = 0.545;
km = 0.040;
m = 0.097;
l = 0.333;
phi = 0.045;
A = 0.017;
B = 0.048;
%unknown parameters;
delta=X(1);
alpha=X(2);
gamma=X(3);
tau=X(4);
theta=X(5);
zeta1=X(6);
zeta2=X(7);
zeta3=X(8);
eta=X(9);
omegae = X(10);
omegam = X(11);
beta = X(12);
F(1) = A*((ke^alpha)*(ne^(1-alpha)))^(1-gamma) * m^gamma - c - ke*phi - km*phi +(ke+km)*(1 - delta);
F(2) = B*(theta * (km^tau) + (1-theta)*(nm^tau))^(1/tau) -m;
F(3) = omegae*se + omegam*nm - phi;
F(4) = 1 - ne - nm - se -l;
F(5) = zeta1 * ke^(alpha*(1-gamma))* ne^(-alpha - gamma*(1- alpha))*m^gamma - c;
F(6) = (gamma/eta)*A*B*(ke^(alpha*(1-gamma)))*(ne^((1-alpha)*(1-gamma)))*(nm^(tau-1))*(m^(gamma - tau)) + c*(omegae /omegam) - c;
F(7) = zeta2 * (ke^((alpha -1)-(gamma*alpha)))*(ne^((1-alpha)*(1-gamma)))*(m^gamma)+ zeta3 - phi;
F(8) = zeta3 - beta * gamma * theta * A* B*(ke^(alpha*(1-gamma)))*(ne^((1-alpha)+(1-gamma)))*(km^(tau-1))*(m^(gamma-tau)) - phi;
F(9) = beta*omegae*(1-l) - phi;
F(10) = (A*(1-gamma)*(1 - alpha))/eta - zeta1;
F(11) = beta*A*(1-gamma)*alpha - zeta2;
F(12) = beta*(1-delta)- zeta3;
  1 个评论
Doug Hates Squirrels
Here's my solution when I try to run it, but I know it's not correct because when I plug the answers into the my system of equations they don't add up
EDU>> fsolve('calibrate',[1 1 1 1 1 1 1 1 1 1 1 1])
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 1200 (the default value).
ans =
0.7982 1.0012 1.1022 0.9963 1.0038 0.0085 0.0001 0.0397 0.9970 0.4465 0.7347 0.1712

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2011-4-26
fsolve(@calibrate, ones(1,12), optimset('MaxFunEvals', 3000, 'FunValCheck', 'on', 'PlotFcns', @optimplotfval))
After your first run, when you have verified that it isn't trying to work with invalid values and have verified that the minimization is going well, you would likely want to remove the last two pairs of options.
  4 个评论
bym
bym 2011-4-26
good thing the question didn't come from "Doug Hates Raccoons"
Paulo Silva
Paulo Silva 2011-4-26
proecsm that was a nice joke, thanks :D

请先登录,再进行评论。

更多回答(1 个)

Lidianne Mapa
Lidianne Mapa 2018-1-14
Hello dear, I'm with similar problem. This is my function:
if y==1
N1{y}=[(diff(Beta{y}(:,1),qsol(1))) diff(Beta{y}(:,1),qsol(2)) diff(Beta{y}(:,1),qsol(3));
(diff(Beta{y}(:,2),qsol(1))) diff(Beta{y}(:,2),qsol(2)) diff(Beta{y}(:,2),qsol(3));
(diff(Beta{y}(:,3),qsol(1))) diff(Beta{y}(:,3),qsol(2)) diff(Beta{y}(:,3),qsol(3))]
N2{y}=[(diff(Alfa{y}(:,1),qsol(1))) diff(Alfa{y}(:,1),qsol(2)) diff(Alfa{y}(:,1),qsol(3));
(diff(Alfa{y}(:,2),qsol(1))) diff(Alfa{y}(:,2),qsol(2)) diff(Alfa{y}(:,2),qsol(3));
(diff(Alfa{y}(:,3),qsol(1))) diff(Alfa{y}(:,3),qsol(2)) diff(Alfa{y}(:,3),qsol(3))]
else
N1{y}=[(diff(Beta{y}(:,1),qsol(4))) diff(Beta{y}(:,1),qsol(5)) diff(Beta{y}(:,1),qsol(6));
(diff(Beta{y}(:,2),qsol(4))) diff(Beta{y}(:,2),qsol(5)) diff(Beta{y}(:,2),qsol(6));
(diff(Beta{y}(:,3),qsol(4))) diff(Beta{y}(:,3),qsol(5)) diff(Beta{y}(:,3),qsol(6))]
N2{y}=[(diff(Alfa{y}(:,1),qsol(4))) diff(Alfa{y}(:,1),qsol(5)) diff(Alfa{y}(:,1),qsol(6));
(diff(Alfa{y}(:,2),qsol(4))) diff(Alfa{y}(:,2),qsol(5)) diff(Alfa{y}(:,2),qsol(6));
(diff(Alfa{y}(:,3),qsol(4))) diff(Alfa{y}(:,3),qsol(5)) diff(Alfa{y}(:,3),qsol(6))]
end
end
KNL1=[N1{1},zeros(size(TMgmod{1},1),size(TMgmod{1},2)); zeros(size(TMgmod{1},1),size(TMgmod{1},2)) N1{2}];
KNL2=[[N2{1},zeros(size(TMgmod{1},1),size(TMgmod{1},2)); zeros(size(TMgmod{1},1),size(TMgmod{1},2)) N2{2}]] KTOTAL=1/2*KNL1+1/3*KNL2+Ktotal Forca=[10;10;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0] TFORCA=Tcbacop'*Forca; x0=inv(Ktotal)*TFORCA fun_sym =rootedo(qsol,KTOTAL,TFORCA); fun = matlabFunction(fun_sym, 'vars', {qsol.'}); fsolve(fun,x0, optimset('MaxFunEvals', 3000,'MaxIter', 800, 'FunValCheck', 'on', 'PlotFcns', @optimplotfval))
function [F]=rootedo(qsol,KTOTAL,TFORCA) F=KTOTAL*qsol'-TFORCA
This error:
fsolve stopped because the relative size of the current step is less than the default value of the step size tolerance squared, but the vector of function values is not near zero as measured by the default value of the function tolerance.
ans = 1.0e-08 * 0.5447 0.1506 0.0561 0.5447 0.1506 0.0561
Can you help me please?

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by