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!