Effacer les filtres
Effacer les filtres

Nonlinear solutions with 7 variables my initial Guess is not working in the program

1 vue (au cours des 30 derniers jours)
syms G;
G = 600:100:1200;
disp(G)
x0 = [310 310 310 311 309 300 300];%initial guess
options = optimoptions('fsolve','Display','off');
X = zeros(1,length(G)); % use X, instead of X(i), initialize with zeros
for i = 1:length(G) % start the loop counter from 1
fsol = fsolve(@(x) solutionsproblem(x,G(i)),x0,options);
X(i,:) = fsol; end
Tg1 = x(:,1); Tg2 = x(:,2); Ta = x(:,3); Tl = x(:,4); Tf = x(:,5); Tb = x(:,6); Th = x(:,7);
disp(X);
function F = solutionsproblem(x,G)
syms N;
syms A;
%assign values to constants
N = 15;
A = 1;
Tg1 = 300;
Tg2 = 301.5;
Ta = 305.8;
Tl = 302;
Tf = 302;
Tb = 302;
Th = 300;
F(1) = 0.0425*G + 1.417*10^(-8)*x(2)^(4) + 0.95*x(2) - 1.967*10^(-8)*x(1)^(4) + 1098.572 - 2404.5*x(1) + 2400*Tg1;
F(2) = 0.0204*G + (-4.888*10^(-8) - 7.709*10^(-11)*N*A)*x(2)^(4) + 1.41*10^(-8)*x(1)^(4) + 4.54*10^(-10)* x(4)^(4) + 3.08*10^(-8)*x(3)^(4) + 7.709*10^(-11)*N*A*x(5)^(4) + 0.55*x(3) + 0.95*x(1) - 2401.5*x(2) - 2400*Tg2;
F(3) = 0.124*G - 6.098*10^(-8)*x(3)^(4) + 3.049*10^(-8)*x(2)^(4) + 3.049*10^(-8)*x(5)^(4)- 568.69*x(3) + 0.236*x(6) + 1.183* x(2) + 567.9*Ta;
F(4) = 4.06*10^(-3)*G - 90.37*10^(-10)*x(4)^(4) + 9.88*10^(-10)*x(7)^(4)+ 9.88*10^(-10)*x(2)^(4) + 0.08*x(7) + 0.044*x(3) + 0.044*x(2) - 132.687*x(4) + 132.44*Tl;
F(5) = 3.686*10^(-4)*N*A*G + 3.049*10^(-8)*x(3)^(4) + 7.7*10^(-11)*x(2)^(4) - 3.056*10^(-8)*x(5)^(4) + 3.88*10^(-4)*N*x(6) + 3.52*10^(-3)*N*A*(x(3) + x(2)) - (3.88*10^(-4)*N + 7.04*10^(-3)*N*A + 215)*x(5) - 215*Tf;
F(6) = 0.386*x(3) + 0.18362*x(7) + 3.88*10^(-4)*N*x(5) + 0.1*x(2) - (194.269 + 3.88*10^(-4)*N)*x(5) + 193.6*Tb;
F(7)= 0.08*x(4) + 9.88*10^(-10)*(x(4)^(4) - x(7)^(4)) + 0.0706*x(6) - 838.79*x(7) + 838.22*Th;
end

Réponses (1)

Ameer Hamza
Ameer Hamza le 4 Mai 2020
What do you mean by "not working"? The value of solutionsproblem at the points found by fsolve() is on the order of 1e-9. You can further tighten this tolerance value, but I guess this should be sufficient enough for most practical applications. Add the following for-loop at the end of your code and check the output in the command window
for i=1:length(G)
y = solutionsproblem(X(i,:), G(i));
disp(y)
end
Result
1.0e-09 *
0.1164 0.1164 0 -0.0073 0.0509 0.0073 -0.0291
1.0e-09 *
0.1164 0 -0.0582 -0.0073 0.0291 0 0.0873
1.0e-09 *
-0.1164 -0.1164 0.0291 0 -0.0437 0 -0.0291
1.0e-09 *
0.1164 0.1164 0.1455 -0.0073 0.0509 0.0073 0.0582
1.0e-09 *
-0.1164 0.1164 0.1455 0 0 0.0073 -0.0291
1.0e-09 *
0 0 0.1746 -0.0073 -0.0146 0 0.0291
1.0e-09 *
-0.1164 -0.1164 0.1164 0 0 0.0146 0.0291
  6 commentaires
Adithya Valavi
Adithya Valavi le 5 Mai 2020
What changes did you make to get this output
Ameer Hamza
Ameer Hamza le 5 Mai 2020
I guess Alex used 1stOpt. That is not a Mathworks product. fsolve() also gives the same solution. It is just printed differently by default. For example, you can display MATLAB solution like this too
for i=1:length(G)
fprintf([repmat('%12f\t', 1, 7) '\n'], X(i,:));
end
Result
299.764157 -254.604230 1378.428104 302.586580 304.130925 3517902.198484 595.784285
299.765923 -254.603474 1378.427393 302.589584 304.130920 3517846.020400 595.779562
299.767689 -254.602717 1378.426682 302.592588 304.130914 3517789.842313 595.774839
299.769455 -254.601960 1378.425971 302.595592 304.130909 3517733.664223 595.770116
299.771221 -254.601204 1378.425260 302.598596 304.130903 3517677.486131 595.765393
299.772986 -254.600447 1378.424549 302.601601 304.130898 3517621.308036 595.760670
299.774752 -254.599690 1378.423838 302.604605 304.130892 3517565.129939 595.755947

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by