mkdir matlab # Make directory (if not made already) cd matlab # go there emacs startup.m &This is an m-file containing Matlab-commands. It makes all m-files in these directories visible (and usable) to you. (You can include any Matlab-commands you want to be executed in the beginning of your Matlab- session.)
path(path,'/p/edu/matlab'); % path(path,'/p/edu/matlab/mathews/'); % path(path,'/p/edu/matlab/piche/'); path(path,'/p/edu/mat-1.174/matlab'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap2/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap3/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap4/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap5/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap6/') path(path,'/p/edu/mat-1.174/matlab/cooper/chap7/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap8/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap9/'); path(path,'/p/edu/mat-1.174/matlab/cooper/chap10/'); % path(path,'/p/edu/mat-1.192/matlab');
If you don't like this, you can work in the Matlab window only (make it large enough). Give the command
>> diary mysession.txt >> command1 >> ... >> diary offThen all the inputs and outputs produced between these two diary commands will be written to the file mysession.txt (and also echoed on the terminal). If you work this way you should tidy up and add comments into the session file afterwards. Of course this requires you to remember to put diary on before you start to produce something worth saving.
I personally prefer the cut/paste-way of working but you are free to disagree.
>> x = []; for i = 1:n, x=[x,i^2], end % This is misuse of Matlab > x:=[];for i to 4 do x:=[op(x),i^2] od; # This is misuse of Maple >> 1:5 % Do this instead > $1..5; # Do this instead or > seq(i,i=1..5); Table of values >> x = [0.0:0.1:2.0]'; > x:=[seq(i*0.1,i=0..20)]: >> y = sin(x); > y:=map(sin,x): >> [x y] > matrix([x,y]); linalg[transpose](%);
>> A=[0 -6 -1;6 2 -16;-5 20 -10] A = 0 -6 -1 6 2 -16 -5 20 -10 >> x0=[1,1,1]' x0 = 1 1 1 >> X=[]; >> for t=0:.01:1 X=[X,expm(t*A)*x0];end >> size(X) ans = 3 101 >> plot3(X(1,:),X(2,:),X(3,:)) >> grid >> figure;plot(X(1,:),X(2,:)) >>
% seuler.m -- Let's agree to take initial s for 'session' or 'script' % (as opposed to function) m=2; hold on; % cut/paste into Matlab-session: "up-arrow-iterate" [T,Y]=meuler('fode1',0,3,2,m); plot(T,Y,'r',T,Y,'o');[T' Y'],m=2*m; [t0,y0]=ginput(1);[T,Y]=meuler('fode1',t0,4,y0,m); plot(T,Y,'r');
% Direction field m-file (script) % Source: Bäckström: Praktisk matematik med Matlab clear variables; hold off; xmax=4; ymax=3; delx=xmax/30; dely=ymax/30; % *** problem dependent [X,Y]=meshgrid(0:delx:xmax,0:dely:ymax); DX=ones(size(X)); % Unit x-xomponents of arrows DY=fode1(X,Y); % Slopes, *** Change the name 'fode' to your m-file name L=sqrt(DX.^2+DY.^2); % Initial lengths DX1=DX./L; DY1=DY./L; % Unit length for all arrows %figure(1); quiver(X,Y,DX1,DY1,'.'); grid on; % The period ('.') suppresses % arrowheads figure(1); quiver(X,Y,DX1,DY1); grid on; axis([0 xmax 0 ymax]); title('Direction field');
fode1.m
function yp=fode1(X,Y); yp=-Y;