Bob
Bob

Reputation: 354

Using Scilab to solve a two equations

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.

Bob

Upvotes: 0

Views: 1333

Answers (1)

user5694329
user5694329

Reputation: 412

function c=f(xy),x=xy(1);y=xy(2);c=[(x+y-8);(2*x+y-8)];endfunction    
fsolve([0;0],f)

Upvotes: -1

Related Questions