Failure in initial objective function evaluation. FSOLVE cannot continue.
1 次查看(过去 30 天)
显示 更早的评论
I want to use fsolve in loop so that every time 'a' change, my X(1) value change and my other values change accordingly. Can anyone help with it And Also can you plot x1 and y1? Any help would be appreciated.
function F = Sample13(X,a)
x1=X(1);
x2=X(2);
y1=X(3);
y2=X(4);
p1sat=X(5);
p2sat=X(6);
p=X(7);
t=X(8);
f1 = p1sat-(exp(16.59158 -(3643.31/(t -33.424))));
f2 = p2sat-(exp(14.25326 -(2665.54/(t -53.424))));
f3 = p - 101.325;
f4 = x1 - a;
f5 = x1 + x2 - 1;
f6 = y1 + y2 - 1;
f7 = (y1*p)-(x1*p1sat);
f8 = (y2*p)-(x2*p2sat);
F=[f1;f2;f3;f4;f5;f6;f7;f8];
end
To Run Function M using this command:
fhandle=@Sample13;
for a=1:0.05:2
X0 = [0.5,0.5,0.5,0.5,200,200,101.325,333.9];
options = optimset('display','off');
X = fsolve(fhandle,X0,options);
disp(X)
end
0 个评论
采纳的回答
Mischa Kim
2021-1-2
编辑:Mischa Kim
2021-1-2
Ahmed, use the following:
fhandle = @Sample13;
options = optimset('display','off','Algorithm','levenberg-marquardt');
a = 1:0.05:2;
for ii = 1:numel(a)
X0 = [0.5,0.5,0.5,0.5,200,200,101.325,333.9,a(ii)];
X = fsolve(fhandle,X0,options);
disp(X)
end
function F = Sample13(X)
x1=X(1);
x2=X(2);
y1=X(3);
y2=X(4);
p1sat=X(5);
p2sat=X(6);
p=X(7);
t=X(8);
a = X(9);
f1 = p1sat-(exp(16.59158 -(3643.31/(t -33.424))));
f2 = p2sat-(exp(14.25326 -(2665.54/(t -53.424))));
f3 = p - 101.325;
f4 = x1 - a;
f5 = x1 + x2 - 1;
f6 = y1 + y2 - 1;
f7 = (y1*p)-(x1*p1sat);
f8 = (y2*p)-(x2*p2sat);
F=[f1;f2;f3;f4;f5;f6;f7;f8];
end
Essentially, you treat a as another function input.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!