Unbalanced or unexpected parenthesis or bracket.

1 view (last 30 days)
Please help, I am trying to solve a system of equations and I keep getting error messages. I am copy and pasting the exact code that was given to me as an example but it is still not working. Here is the code:
function f6 =nle(x)
f6(1) =x(1)^2+x(2)^2-5;
f6(2)=x(1)*x(2)-2 ;
x0 = [1 1]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display outputx
x= fsolve('nle',x0;options) % Call solver

Answers (1)

Walter Roberson
Walter Roberson on 5 Oct 2015
You need to store
function f6 =nle(x)
f6(1) =x(1)^2+x(2)^2-5;
f6(2)=x(1)*x(2)-2 ;
in a file nle.m
and you would store
x0 = [1 1]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display outputx
x= fsolve('nle',x0, options) % Call solver
in a different file and execute it. These lines cannot be in the same file as the above.
The error in your code is that you have
x= fsolve('nle',x0;options) % Call solver
which has a semi-colon where it needs a comma.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!