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

조회 수: 2 (최근 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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get 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