How to solve this system of nonlinear equations composed of symbolic variables

2 visualizaciones (últimos 30 días)
Hi
I want to solve 3 nonlinear equations with 2 unknowns. The equations are composed of symbolic variables. When I run the code it gives the error " too many input arguments". I have spent lots of hours but could not resolve it. Any help or other solutions are really appreciated.
BTW, this code is one of several functions of the major code(i.e. A(i), beta(i), l(i) and j(i) are calculated in a separate function.
eqn1 = sumf == 0;
eqn2 = sumff == 0;
eqn3 = summ == 0;
F=@(x,y)[eqn1;eqn2;eqn3];
fun=@(u) F(u(1),u(2),u(3));
x0=[1 .5 ;1 .5; 1 .5];
[u1,fval1]=fsolve(fun,x0),

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Jul. de 2020
F=@(x,y)[eqn3;eqn4;eqn5];
Okay, F takes two arguments and ignores them and returns an array of items based on symbolic x and y and possibly other things (we cannot see the code for eqn4 or eqn5.)
fun=@(u) F(u(1),u(2),u(3));
fun takes a vector of 3 or more items and passes the first 3 one by one to the function F that is only expecting two parameters.
Let me emphasize that the parameters you pass to F are going to be ignored. When you construct the array for fun then the values that are going to be captured in the anonymous function will be the x and y that are symbolic variables. if you want the x and y padded in to be used in the expression then subs() them into the vector of equations.
But you are passing the function to fsolve. fsolve does not expect symbolic results. It also cannot proceed properly with == expressions
You should either use vpasolve or else you should leave out the ==0 should use matlabFunction() to construct numeric functions to fsolve
  7 comentarios
Walter Roberson
Walter Roberson el 6 de Jul. de 2020
Editada: Walter Roberson el 6 de Jul. de 2020
you have two variables, x and y. You should not be passing in 6 initial conditions.
Note that fsolve does not permit passing in ranges of values for the variables. fzero permits a range of values for its single variable, and vpasolve permits ranges of values for each variable, but fsolve only permits initial conditions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by