Solving Nonlinear System of Equations with 10 variables
64 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to solve the system of equations below but I keep running into problems. I tried to solve it with fsolve, but it would always return an error saying "FSOLVE requires all values returned by functions to be of data type double." or would just run forever and I would have to force stop it. I looked into doing the Newton-Raphson method, but I didn't want to manually type 100 different partial derivatives. If anyone knows a good way to solve this, I would realy appreciate it.
clc
W=100;
s=10;
S=23;
F=13;
m=9;
eqn1= 5-(W+S*9)*X1+S*9*X2-S*20*X1^2+S*20*X2^2==0;
eqn2= W*X1-(W+S*9)*X2+S*9*X3-S*20*X2^2+S*20*X3^2==0;
eqn3= W*X2-(W+S*9)*X3+S*9*X4-S*20*X3^2+S*20*X4^2==0;
eqn4= W*X3-(W+S*9)*X4+S*9*X5-S*20*X4^2+S*20*X5^2==0;
eqn5= W*X4-(W+S*9)*X5+S*9*X6-S*20*X5^2+S*20*X6^2==0;
eqn6= W*X5-(W+S*9)*X6+S*9*X7-S*20*X6^2+S*20*X7^2==0;
eqn7= 0.039+W*X6+(-W+9*S)*X7-9*s*X8+20*S*X7^2-20*s*X8^2==0;
eqn8= W*X7-(W+9*s)*X8-9*s*X9-20*s*X8^2-20*s*X9^2==0;
eqn9= W*X8-(W+9*s)*X9-9*s*X10-20*s*X9^2-20*s*X10^2==0;
eqn10=W*X9-(W+9*s)*X10-20*s*X10^2==0;
0 件のコメント
回答 (2 件)
John D'Errico
2022 年 11 月 24 日
Use fsolve. You are trying to formulate this in terrm of a symbolic variables, but fsolve is a NUMERICAL solver. So you need to write this in terms of a function, that returns a vector of length 10, as a function of the vector x, also of length 10.
fsolve does not like symbolic variables. Again, they are not numbers. So fsolve will have a fit.
2 件のコメント
Walter Roberson
2022 年 11 月 24 日
matlabFunction() and use the 'vars' option with a cell array that is a single entry that is a vector of the variable names (giving the order to use them)
Torsten
2022 年 11 月 24 日
W=100;
s=10;
S=23;
%F=13;
%m=9;
fun = @(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10)...
[5-(W+S*9)*X1+S*9*X2-S*20*X1^2+S*20*X2^2
W*X1-(W+S*9)*X2+S*9*X3-S*20*X2^2+S*20*X3^2
W*X2-(W+S*9)*X3+S*9*X4-S*20*X3^2+S*20*X4^2
W*X3-(W+S*9)*X4+S*9*X5-S*20*X4^2+S*20*X5^2
W*X4-(W+S*9)*X5+S*9*X6-S*20*X5^2+S*20*X6^2
W*X5-(W+S*9)*X6+S*9*X7-S*20*X6^2+S*20*X7^2
0.039+W*X6+(-W+9*S)*X7-9*s*X8+20*S*X7^2-20*s*X8^2
W*X7-(W+9*s)*X8-9*s*X9-20*s*X8^2-20*s*X9^2
W*X8-(W+9*s)*X9-9*s*X10-20*s*X9^2-20*s*X10^2
W*X9-(W+9*s)*X10-20*s*X10^2];
Fun = @(x)fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10));
format long
sol = fsolve(Fun,ones(10,1))
norm(Fun(sol))
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!