Failure in initial objective function evaluation. FSOLVE cannot continue.

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

 采纳的回答

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 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by