matlab - error in two dimensional secand method -


i want understand error in following code?code given below

function x0=secand2d(f,g,x,dx,tol) % find solution of f(x,y)=0 , g(x,y)=0 i=1:20     x0=x;     f0=[feval(f,x0),feval(g,x0)];    x0=x+[dx(1),0];    fx=[feval(f,x0),feval(g,x0)];    fx=(fx-f0)/dx(1);    x0=x+[0 dx(2)];    fy=[feval(f,x0),feval(g,x0)];    fy=(fy-f0)/dx(2);    a=[fx;fy]+eps;    x=x+dx;    dx=(-a\f0'-dx')';    if(norm(dx)<tol) ;return; end; end;   disp(norm(dx));  pause;  end 

which represents of 2 dimensional secant method,where function f , g defined following form

f=@(x,y) (x-sin(x+y)); ,   g=@(x,y) y-cos(x-y); 

i have checked , these function works fine on it's parameters

f(3,3)  ans =      3.2794 

and

g(1,1)  ans =       0 

also

x=[0.9 0.9]; dx=[0.1 0.1]; tol=1e-5; 

but following code generated such kind of errors

secand2d(f,g,x,dx,tol) error using @(x,y)(x-sin(x+y)) not enough input arguments.  error in secand2d (line 5)     f0=[feval(f,x0),feval(g,x0)]; 

please me clarify reasons of errors

you getting error because passing x0 f here:

f0=[feval(f,x0),feval(g,x0)]; 

f , g expecting 2 inputs. can fix error this:

f0=[feval(f,x0,y0),feval(g,x0,y0)]; 

if there not particular reason using feval can this:

f0 = [f(x0, y0) g(x0, y0)]; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -