i need to solve 7 nonlinear equations with 7 unknowns and error is occurring while compiling the codes
2 次查看(过去 30 天)
显示 更早的评论
G = 600:100:1200;
x0 = [300;300;300;300;300;300;300];
options = optimset('Display','off');
X(i) = NaN(1,length(G));
for i = 600:length(G)
fsol = fsolve(@(x) solutionsproblem(x,G(i)),x0,options);
X(i) = fsol(1);
end
function F = solutionsproblem(x,G)
Tg1 = 300;
Tg2 = 301.5;
Ta = 305.8;
Tl = 302;
Tf = 302;
Tb = 302;
Th = 300;
F(1) = 0.0425*G + 1.41*10^(-8)*x(2)^(4) + 1.34*x(2) - 9.12*10^(-9)*x(1)^(4) + 341 - 2402.77*x(1) + 2400*Tg1;
F(2) = 0.0204*G - (3.48*10^(-8) + 4.35*10^(-10)*1)*x(2)^(4) + 1.41*10^(-8)*x(1)^(4) + 8.01*10^(-11)* x(4)^(4) + 2.43*10^(-8)*x(3)^(4) + 4.35*10^(-10)*1*x(5)^(4) + 0.55*x(3) + 1.34*x(1) - 2401.87*x(2) + 2400*Tg2;
F(3) = 0.124*G - 4.88*10^(-8)*x(3)^(4) + 2.44*10^(-8)*1*x(2)^(4) + 2.44*10^(-8)*1*x(5)^(4)- 50.938*x(3) + 11.502*x(6) + 1.836* x(2) + 37.60*Ta;
F(4) = 0.011*G - 8.70*10^(-8)*x(5)^(4) + 4.35*10^(-10)*x(3)^(4)+ 4.35*10^(-10)*x(2)^(4) + 0.83*x(6) + 0.112*x(3) + 0.112*x(2) - (1.055 + (112.7/1))*x(5) + (112.7/1)*Tf;
F(5) = 2.17*10^(-3)*G - 1.6*10^(-10)*x(4)^(4) + 8.01*10^(-11)*x(7)^(4) + 8.01*10^(-11)*x(2)^(4) - 69.07*x(4) + 3.77*10^(-4)*x(7) + 0.02*x(3) + 0.02*x(2) + 69*Tl;
F(6) = -52.068*x(6) + 0.412*x(3) + 0.368*x(4)+ 0.368*x(5) + 0.46*x(2) + 50.78*Tb;
F(7)= 3.77*10^(-4)*x(4) + 8.01*10^(-11)*x(4)^(4) + 0.092*x(5) - 1254.1*x(7) - 8.01*10^(-11)*x(7)^(4) + 1254*Th;
end
3 个评论
David Goodmanson
2020-4-8
Hi Bindhu,
you have not defined the argument of X. Ordinarily if you had, say, X(b) it would complain about the undefined variable b. Here, unless you have already defined i as something else, it is assuming i = sqrt(-1)
采纳的回答
Bindhu PR
2020-4-12
编辑:Ameer Hamza
2020-4-12
3 个评论
Walter Roberson
2020-4-12
编辑:Walter Roberson
2020-4-12
X = zeros(length(G), 7); %initialize with zeros
And in loop
X(i, :) = fsol;
更多回答(2 个)
Ameer Hamza
2020-4-8
编辑:Ameer Hamza
2020-4-12
It is a common practice to initialize arrays with zeros instead of nan. Correct two lines in your code
syms G;
G = 600:100:1200;
x0 = [300;300;300;300;300;300;300];
options = optimset('Display','off');
X = zeros(numel(G), numel(x0)); % use X, instead of X(i), initialize with zeros
for i = 1:length(G) % start the loop counter from 1
X(i,:) = fsolve(@(x) solutionsproblem(x,G(i)),x0,options);
end
disp(X);
function F = solutionsproblem(x,G)
Tg1 = 300;
Tg2 = 301.5;
Ta = 305.8;
Tl = 302;
Tf = 302;
Tb = 302;
Th = 300;
F(1) = 0.0425*G + 1.41*10^(-8)*x(2)^(4) + 1.34*x(2) - 9.12*10^(-9)*x(1)^(4) + 341 - 2402.77*x(1) + 2400*Tg1;
F(2) = 0.0204*G - (3.48*10^(-8) + 4.35*10^(-10)*1)*x(2)^(4) + 1.41*10^(-8)*x(1)^(4) + 8.01*10^(-11)* x(4)^(4) + 2.43*10^(-8)*x(3)^(4) + 4.35*10^(-10)*1*x(5)^(4) + 0.55*x(3) + 1.34*x(1) - 2401.87*x(2) + 2400*Tg2;
F(3) = 0.124*G - 4.88*10^(-8)*x(3)^(4) + 2.44*10^(-8)*1*x(2)^(4) + 2.44*10^(-8)*1*x(5)^(4)- 50.938*x(3) + 11.502*x(6) + 1.836* x(2) + 37.60*Ta;
F(4) = 0.011*G - 8.70*10^(-8)*x(5)^(4) + 4.35*10^(-10)*x(3)^(4)+ 4.35*10^(-10)*x(2)^(4) + 0.83*x(6) + 0.112*x(3) + 0.112*x(2) - (1.055 + (112.7/1))*x(5) + (112.7/1)*Tf;
F(5) = 2.17*10^(-3)*G - 1.6*10^(-10)*x(4)^(4) + 8.01*10^(-11)*x(7)^(4) + 8.01*10^(-11)*x(2)^(4) - 69.07*x(4) + 3.77*10^(-4)*x(7) + 0.02*x(3) + 0.02*x(2) + 69*Tl;
F(6) = -52.068*x(6) + 0.412*x(3) + 0.368*x(4)+ 0.368*x(5) + 0.46*x(2) + 50.78*Tb;
F(7)= 3.77*10^(-4)*x(4) + 8.01*10^(-11)*x(4)^(4) + 0.092*x(5) - 1254.1*x(7) - 8.01*10^(-11)*x(7)^(4) + 1254*Th;
end
11 个评论
Bindhu PR
2020-4-13
10 个评论
Walter Roberson
2020-4-28
If you want to print out the values of x(1) to x(7), why not just disp() the values? You have already shown that you know how to use disp(), so we do not understand why you are asking this question. It tends to suggest to us that you want something more complicated than just displaying x(1) to x(7).
I already showed you in https://www.mathworks.com/matlabcentral/answers/516059-i-need-to-solve-7-nonlinear-equations-with-7-unknowns-and-error-is-occurring-while-compiling-the-cod#comment_827486 how to store all of the values as you compute them, and put them into the various named variables; it would be trivial to add appropriate disp() to that. But you seemed to want something else other than what I suggested and did not reply to me, and you did not explain how what you wanted differed from what I suggested to you; it did not seem to be worth my time to keep asking you questions about what you really wanted.
You are getting 7 outputs for each of the 7 values of G. Give us an example of how you would like the output to look.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!