How to solve N nonlinear equations using fsolve?
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm trying to solve a system on N nonlinear equations. For
, for example, I can simply input 5 equations by hand that has 5 variables in total. Here's an example just to show what I use;

%%%%% Example %%%%%
f=@(x) [x(1)^2-x(2);
x(2)^2-x(3);
x(3)^2-x(4);
x(4)^2-x(5);
x(5)^2-x(1)];
X=ones(1,N-3);
S=fsolve(f,X);
%%%%% Example %%%%%
What I really want to do is to solve N nonlinear equations that has N variables in total. In this case there are 2 issues I need to solve.
1-) How can I input N variables?
2-) How can I input N functions?
Is there any loop I can use?
Thanks in advance.
댓글 수: 1
Walter Roberson
2020년 5월 3일
do you have the symbolic toolbox? if so then create a vector of equations and matlabFunction that
채택된 답변
Walter Roberson
2020년 5월 3일
If you do not have the symbolic toolbox, you will need to enter the equations as text. strjoin() the equations with ';' and put '@(x)[' ']' around that, and str2func() to create the function handle.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!