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

1 回表示 (過去 30 日間)
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),

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 5 日
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 件のコメント
Walter Roberson
Walter Roberson 2020 年 7 月 6 日
編集済み: Walter Roberson 2020 年 7 月 6 日
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.
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2020 年 7 月 6 日
Great help! Many thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by