<PRE>function implot(fun,rangexy,ngrid)<BR>% Implicit plot function<BR>% function implot(fun,rangexy,ngrid)<BR>% fun is 'inline' function f(x,y)=0 (Note function written as equal to zero)<BR>% rangexy =[xmin,xmax,ymin,ymax] range over which x and y is ploted default(-2*pi,2*pi)<BR>% ngrid is the number of grid points used to calculate the plot,<BR>% Start with course grid (ngrid =20) and then use finer grid if necessary<BR>% default ngrid=50<BR>%<BR>% Example <BR>% Plot y^3+exp(y)-tanh(x)=0<BR>%<BR>% write function f as an 'inline' function of x and y-- right hand side <BR>% equal to zero<BR>%<BR>% f=inline('y^3+exp(y)-tanh(x)','x','y')<BR>% implot(f,[-3 3 -2 1])<BR><BR><BR>% A.Jutan UWO 2-2-98 ajutan@julian.uwo.ca<BR><BR><BR><BR>if nargin == 1 ;% grid value and ranges not specified calculate default<BR> rangexy=[-2*pi,2*pi,-2*pi,2*pi];<BR> ngrid=50;<BR>end<BR><BR><BR>if nargin == 2; % grid value not specified<BR> ngrid=50;<BR>end<BR><BR><BR>% get 2-D grid for x and y<BR><BR><BR>xm=linspace(rangexy(1),rangexy(2),ngrid);<BR>ym=linspace(rangexy(3),rangexy(4),ngrid);<BR>[x,y]=meshgrid(xm,ym);<BR>fvector=vectorize(fun);% vectorize the inline function to handle vectors of x y<BR>fvalues=feval(fvector,x,y); %calculate with feval-this works if fvector is an m file too<BR>%fvalues=fvector(x,y); % can also calculate directly from the vectorized inline function<BR>contour(x,y,fvalues,[0,0],'b-');% plot single contour at f(x,y)=0, blue lines<BR>xlabel('x');ylabel('y');<BR>grid<BR></PRE><BR><BR>用这个函数吧 |