[Scilab-users] Using the Function fsolve

Samuel Gougeon sgougeon at free.fr
Sun Aug 28 22:31:48 CEST 2016


Le 28/08/2016 22:03, Robert Sherry a écrit :
> I defined the following two functions:
>
> function [z]=f(x,y)
> z = x + y - 8
> endfunction
>
> function [z]=g(x,y)
> z = 2*x + y - 8
> endfunction
>
> I then wanted to find the roots of the two functions (equations). That 
> is, I want a pair of numbers (a,b)
> such that f(a,b) = g(a,b) = 0. So, I found the function fsolve in the 
> documentation of Scilab which I believe will do what I want. So, I ran 
> the following command:
>         fsolve([0;0],f,g)
> and it produced the following error:
>        Undefined variable: y
>        at line       2 of function f called by :
>        fsolve([0;0],f,g)
> I do not understand this error and I am hoping that somebody can tell 
> me what I am doing wrong.

You problem is linear. So there are simpler solutions than fsolve() that 
is useful for systems of non-linear equations.
Your system is equivalent to the matrix equation
[1 1 ; 2 1]*X = [ 8 ; 8]  with X = [x ; y]
Let set
A = [1 1 ; 2 1] ;
// and
b = [ 8 ; 8];
// from A*X = b, we get X with
X = A\b
--> X = A\b
  X  =
    0.
    8.
that means { x=0, y=8 }

Regards
Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160828/f6fc2d0e/attachment.htm>


More information about the users mailing list