help-octave
[Top][All Lists]

## Re: Using fsolve to solve example problem from documentation gives very

 From: Steven Davis Subject: Re: Using fsolve to solve example problem from documentation gives very different result Date: Wed, 14 Oct 2015 14:40:25 -0500

I went to my download folder and deleted the Octave installation zip file and the unzipped folder.  Then I went to the editor, copied the function definition
function y=f(x)
y=zeros(2,1);
y(1)=-2*x(1)^2+3*x(1)*x(2)+4*sin(x(2))-6;
y(2)=3*x(1)^2-2*x(1)*x(2)^2+3*cos(x(1))+4;
endfunction

and did a save as f.m

Now when I try fsolve I get the following:

>> [x,fval,info]=fsolve(@f,[1;2])
stopped in C:\Octave\Octave-4.0.0\share\octave\4.0.0\m\optimization\fsolve.m at line 140
140:   if (nargin == 1 && ischar (fcn) && strcmp (fcn, 'defaults'))
debug>

At least this gives me something to chew on...

On Wed, Oct 14, 2015 at 1:30 PM, Doug Stewart wrote:

On Wed, Oct 14, 2015 at 12:40 PM, Steven Davis wrote:
Hi,

I was trying to use fsolve to solve a system of equations, and couldn't get it to work.  So I decided to try entering the example from the Octave documentation, Chapter 20 page 505. I figured once I got that to run I could work my way through to figure out what I was doing wrong.  But I couldn't get fsolve to give the same result the documentation example said I should get!

I entered into the editor and saved as f.m the following:

function y=f(x)
y=zeros(2,1);
y(1)=-2*x(1)^2+3*x(1)*x(2)+4*sin(x(2))-6;
y(2)=3*x(1)^2-2*x(1)*x(2)^2+3*cos(x(1))+4;
endfunction

I then entered into the command window:

[x,fval,info]=fsolve(@f,[1;2])

According to the documentation I should get:

x =
0.57983
2.54621
fval =
-5.7184e-10
5.5460e-10
info = 1

I tried a copy and past from here and it worked
ans =  1
x =

0.57983
2.54621

fval =

-2.8991e-08
4.9167e-07

info =  1
>>

So I think you have a different file named fsolve.m somewhere in your path.
Doug