M FILES


example1.m                      (file name)--------------------x=1:5;y=2.^x;plot(x,y)


%TYPE

>> example1

image

*Same as typing in directly

FUNCTIONS

  • Fourier Series expansion for sawtooth wave

term.m (file name) -------------------- function y=term(t,k) y=(2/pi)*(-1)^(k+1); y=y/k; y=y.*sin(k*pi*t);



>> t=-2:0.05:2; >> y1=term(t,1); >> y2=term(t,2); >> plot(t,y1,t,y2) image


example2.m (file name) -------------------- t=-2:0.05:2; y=0*t; for k=1:10 y=y+term(t,k); end plot(t,y)



>> example2 image >> print (prints to printer) >> print sawtooth.ps -dps (dumps postscript)