Nonlinear solutions with 7 variables my initial Guess is not working in the program
Show older comments
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
Answers (1)
Ameer Hamza
on 4 May 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 Comments
Adithya Valavi
on 4 May 2020
Adithya Valavi
on 4 May 2020
Ameer Hamza
on 4 May 2020
Not necessarily near x0. This is just an initial guess. Are you sure that a solution of the equations lies near x0? Also note that the variables 1,2,4, and 5 are near 300. Only 3 and 6 are far.
Alex Sha
on 5 May 2020
I got the result below:
G x1 x2 x3 x4 x5 x6 x7
600 299.764156633882 -254.604230258111 1378.42810435931 302.586579569078 304.130925344338 3517902.19848446 595.784285276060
700 299.765922601135 -254.603473577461 1378.42739326552 302.589583773355 304.130919856780 3517846.02039974 595.779562215228
800 299.767688568363 -254.602716896794 1378.42668217067 302.592587977665 304.130914369218 3517789.84231252 595.774839154086
900 299.769454535567 -254.601960216108 1378.42597107476 302.595592182008 304.130908881655 3517733.66422282 595.770116092635
1000 299.771220502746 -254.601203535404 1378.42525997780 302.598596386383 304.130903394089 3517677.48613064 595.765393030875
1100 299.772986469899 -254.600446854683 1378.42454887978 302.601600590791 304.130897906520 3517621.30803596 595.760669968806
1200 299.774752437028 -254.599690173943 1378.42383778070 302.604604795231 304.130892418949 3517565.12993881 595.755946906428
Adithya Valavi
on 5 May 2020
Ameer Hamza
on 5 May 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
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!