help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fslove using Jacobian


From: Tatsuro MATSUOKA
Subject: Re: fslove using Jacobian
Date: Tue, 15 Jun 2010 08:40:06 +0900 (JST)

Hello

Worked!! Thanks!!.

 If `"Jacobian"' is `"on"', it specifies that FCN, called with 2
    output arguments, ..............

I did not understand '2 output arguments'(sigh to myself!!)

Regards

Tatsuro


--- Thomas Shores wrote:

> The documentation is a bit vague on this point, but the syntax of fsolve 
> has changed.  Try this
> 
> # fslovetest.m
> 1;
> function [y,J] = f(x)
>    y = zeros(size(x));
>    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;
>    if (nargout == 2)
>      J(1,1) =  3*x(2) - 4*x(1);
>      J(1,2) =  4*cos(x(2)) + 3*x(1);
>      J(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1);
>      J(2,2) = -4*x(1)*x(2);
>    end
> endfunction
> [x, fval, info] = fsolve (@f, [1; 2],optimset("Jacobian","on"))
> # end of fslovetest.m
> 
> Resulting output:
> 
> octave:1> fsolvetest
> x =
> 
>     0.57983
>     2.54621
> 
> fval =
> 
>     6.1872e-08
>    -3.2708e-07
> 
> info =  1
> 
> 
> On 06/14/2010 03:17 AM, Tatsuro MATSUOKA wrote:
> > Hello
> >
> > I am now revising my documentations for my lecture concerning the octave.
> >
> > > From octave 3.2, fslove are improved extensively.
> >
> > In the octave manual (3.2.4)
> >
> > An example, fsolve using Jacobian, is written as,
> >
> >
> > function y = f (x)
> >         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
> >
> > function J = jacobian(x)
> >         J(1,1) =  3*x(2) - 4*x(1);
> >         J(1,2) =  4*cos(x(2)) + 3*x(1);
> >         J(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1);
> >         J(2,2) = -4*x(1)*x(2);
> > endfunction
> >
> > [x, fval, info] = fsolve (address@hidden, @jacobian}, [1; 2]);
> > *********************************************
> >
> > So I made a script,
> >
> > # fslovetest.m
> >
> > 1;
> > function y = f (x)
> >         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
> >
> > function J = jacobian(x)
> >         J(1,1) =  3*x(2) - 4*x(1);
> >         J(1,2) =  4*cos(x(2)) + 3*x(1);
> >         J(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1);
> >         J(2,2) = -4*x(1)*x(2);
> > endfunction
> >
> > [x, fval, info] = fsolve (address@hidden, @jacobian}, [1; 2])
> >
> > # end of fslovetest.m
> >
> > For, octave 3.0, it works as written in manual.
> >
> > octave.exe:3>  fslovetest
> > x =
> >
> >     0.57983
> >     2.54621
> >
> > fval =
> >
> >    -5.7184e-010
> >    5.5461e-010
> >
> > For octave 3.2,
> >
> > octave-3.2.4.exe:3>  fslovetest
> > error: xnorm: wrong type argument `cell'
> > error: called from:
> > error:   
> > C:\Programs\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\optimization\fsolve.m
> >  at line
> 180,
> > column 6
> > error:   D:\usr\Lecture\ .....\work\fslovetest.m at line 14, column 18
> >
> > In the same manual (and in help fsolve), example of the use-defined 
> > function,
> > ****
> > function [fvec, fjac] = user_func (x, optimvalues, state)
> >   :
> >
> > ******
> >
> > The example of the manual is obviously obsolete.
> > Unfortunately I have never seen the manual generated in octave-3.3.51+ 
> > because of the latex
> problem. I
> > do not know the latest manual.
> >
> > I have tried
> >
> > # fslovetest2.m
> > 1;
> > function y = f (x)
> >         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
> >
> > function J = jacobian(x)
> >         J(1,1) =  3*x(2) - 4*x(1);
> >         J(1,2) =  4*cos(x(2)) + 3*x(1);
> >         J(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1);
> >         J(2,2) = -4*x(1)*x(2);
> > endfunction
> >
> > function f = fcn(x)
> >         f=[(f(x)).', jacobian(x)];
> > endfunction
> >
> >
> > [x, fval, info]=fsolve (@fcn, [1; 2],optimset("Jacobian","on"))
> > # end of fslovetest2.m
> >
> > error: element number 2 undefined in return list
> > error: called from:
> > error:   
> > C:\Programs\Octave\3.2.4_gcc-4.4.0\share\octave\3.2.4\m\optimization\fsolve.m
> >  at line
> 204,
> > column 21
> > error:   D:\usr\Lecture\ ..........\work\fslovetest2.m at li
> > ne 19, column 1
> >
> >
> > How should I correct the fsolve script using Jacobian on octave 3.2 or 
> > later in the example
> for the
> > octave 3.0?
> >
> > Regards
> >
> > Tatsuro
> >
> >
> >
> >
> >
> >
> > --------------------------------------
> > 2010 FIFA World Cup News [Yahoo!Sports/sportsnavi]
> > http://pr.mail.yahoo.co.jp/southafrica2010/
> > _______________________________________________
> > Help-octave mailing list
> > address@hidden
> > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> >    
> 
> 


--------------------------------------
2010 FIFA World Cup News [Yahoo!Sports/sportsnavi]
http://pr.mail.yahoo.co.jp/southafrica2010/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]