Solving Nonlinear System of Equations with 10 variables

6 views (last 30 days)
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;

Answers (2)

John D'Errico
John D'Errico on 24 Nov 2022
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 Comments
Walter Roberson
Walter Roberson on 24 Nov 2022
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)

Sign in to comment.


Torsten
Torsten on 24 Nov 2022
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))
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
sol = 10×1
0.022650801201351 0.010341116968466 0.004585328417275 0.001843921328684 0.000526509707922 -0.000109331562119 -0.000416860856866 -0.000182933614111 -0.000077073111109 -0.000040566527577
norm(Fun(sol))
ans =
7.757362175446520e-14

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!