[Scilab-users] Having a Problem with fsolve Classic List Threaded 7 messages Open this post in threaded view
|

[Scilab-users] Having a Problem with fsolve I am trying to solve a system of two non-linear equations using fsolve. I define the following two functions: function z=g1(x,y) z = x^2 + y^2 endfunction function z=g2(x,y) z = x^4 + y^4 - 20 endfunction When I type something like: g2(2,2) I get 12 which is right. I then run the following command:      [xres]=fsolve([0,0],g1,g2); and I get the error message:      fsolve: exception caught in 'jac' subroutine.      at line     2 of function g1      in builtin                fsolve What am I doing wrong? Bob _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Having a Problem with fsolve Hello, Le 15/10/2018 à 20:39, rsherry8 a écrit : I am trying to solve a system of two non-linear equations using fsolve. I define the following two functions: function z=g1(x,y) z = x^2 + y^2 endfunction function z=g2(x,y) z = x^4 + y^4 - 20 endfunction When I type something like: g2(2,2) I get 12 which is right. I then run the following command:     [xres]=fsolve([0,0],g1,g2); If it is provided, g2() must be the jacobian of g1(): it must compute and evaluate the partial derivatives of g1(), with respect to x and to y. That's definitely not the case with your g2(). It should rather return something like [2*x 2*y]. For what you likely want to do, here are two examples (extracted from a document of mine in french, sorry): Actually, the fsolve() page is rather poor : both given examples are about a single variable. https://help.scilab.org/docs/6.0.1/en_US/fsolve.html fsolve() is a key function. We should improve its help page. HTH Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Having a Problem with fsolve Le 15/10/2018 à 23:52, Samuel Gougeon a écrit : .../... Actually, the fsolve() page is rather poor : both given examples are about a single variable. https://help.scilab.org/docs/6.0.1/en_US/fsolve.html fsolve() is a key function. We should improve its help page. This is now explicitly requested there. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Having a Problem with fsolve In reply to this post by Samuel GOUGEON You Wrote:     If it is provided, g2() must be the jacobian of g1(): it must compute and evaluate the partial derivatives of g1(), with respect to x and to y.     That's definitely not the case with your g2(). It should rather return something like [2*x 2*y]. I do not understand this because I am trying to solve a system of equations and g2 represents the second equation. I suspect I am missing something. I do not know French. Bob On 10/15/2018 5:52 PM, Samuel Gougeon wrote: Hello, Le 15/10/2018 à 20:39, rsherry8 a écrit : I am trying to solve a system of two non-linear equations using fsolve. I define the following two functions: function z=g1(x,y) z = x^2 + y^2 endfunction function z=g2(x,y) z = x^4 + y^4 - 20 endfunction When I type something like: g2(2,2) I get 12 which is right. I then run the following command:     [xres]=fsolve([0,0],g1,g2); If it is provided, g2() must be the jacobian of g1(): it must compute and evaluate the partial derivatives of g1(), with respect to x and to y. That's definitely not the case with your g2(). It should rather return something like [2*x 2*y]. For what you likely want to do, here are two examples (extracted from a document of mine in french, sorry): Actually, the fsolve() page is rather poor : both given examples are about a single variable. https://help.scilab.org/docs/6.0.1/en_US/fsolve.html fsolve() is a key function. We should improve its help page. HTH Samuel _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

Re: Having a Problem with fsolve Le 16/10/2018 à 02:00, rsherry8 a écrit : > You Wrote: > >     If it is provided, g2() must be the jacobian of g1(): it must > compute and evaluate the partial derivatives of g1(), with respect to > x and to y. >     That's definitely not the case with your g2(). It should rather > return something like [2*x 2*y]. > > I do not understand this because I am trying to solve a system of > equations and g2 represents the second equation. I suspect I am > missing something. > > I do not know French. You may mimic the given example #3. You do not need to speak french to try and test the given code, understand, and imitate it for your own case. BR _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users Thank you for your response. I am trying to  solve the following system of equations:      x^2 + y^2 = 0      x^4 + y^4 - 10 = 0 I defined the following function in SciLab:          function y=f3(x,y)              y = [x^2+y^2,x^4+y^4-10]          endfunction That appeared to work. I found that f3(1,1) is:    2.  -8. So I then ran the following:      fsolve([0,0], f3 ) and I got:      fsolve: exception caught in 'fct' subroutine.      at line     2 of function f3      in builtin                fsolve      Undefined variable: y I then defined the function fct as follows:      function y=fct(x,y)          y = [2*x+2*y, 4*x^3+4*y^3]      endfunction I then ran the command:      fsolve([0,0], f3, fct ) and that produced the following message:      fsolve: exception caught in 'jac' subroutine.      at line     2 of function f3      in builtin                fsolve      Undefined variable: y Any additional comments? Thanks, Bob On 10/15/2018 8:14 PM, Samuel Gougeon wrote: > Le 16/10/2018 à 02:00, rsherry8 a écrit : >> You Wrote: >> >>     If it is provided, g2() must be the jacobian of g1(): it must >> compute and evaluate the partial derivatives of g1(), with respect to >> x and to y. >>     That's definitely not the case with your g2(). It should rather >> return something like [2*x 2*y]. >> >> I do not understand this because I am trying to solve a system of >> equations and g2 represents the second equation. I suspect I am >> missing something. >> >> I do not know French. > > You may mimic the given example #3. You do not need to speak french to > try and test the given code, understand, and imitate it for your own > case. > > BR > > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/users> _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users Hello, try with   function out=f3(vect)            x=vect(1);            y=vect(2);            out = [x^2+y^2,x^4+y^4-10]        endfunction Next time take a look at the fsolve examples ! S. > Le 16 oct. 2018 à 02:52, rsherry8 <[hidden email]> a écrit : > >   function y=f3(x,y) >            y = [x^2+y^2,x^4+y^4-10] >        endfunction _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users