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

3 visualizzazioni (ultimi 30 giorni)
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),

Risposta accettata

Walter Roberson
Walter Roberson il 5 Lug 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 Commenti
Walter Roberson
Walter Roberson il 6 Lug 2020
Modificato: Walter Roberson il 6 Lug 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by