2
ME 352 – Spring 2011
Running from the Command Window
> x = 2
> y = 3
> z = x*y
> z = y*sin(1.5*x)
> x = [1,2,3]
> A = [2,1,0;1,2,1;0,1,1]
> y = A*x
> x = x’
> y = A*x
> b = [1;2;3]
> lookfor determinant
> help det
> y(1) = det([b(1),A(1,2);b(2),A(2,2)])
> y(1) = det([b,A(:,1)])
> whos
> clear
> whos
> x = (0:0.01:1)*2*pi
> x = (0:0.01:1)*2*pi;
> y = sin(x);
> plot (x,y)
> z = sin(2*x);
> plot(x,y,x,z)
> xlabel(‘this is the xaxis’)
> ylabel(‘this is the yaxis’)
> gtext(‘y=sin(x)’)
> gtext(‘z=sin(2*x)’)
> b = [x;y;z];
> fid = fopen(‘stuff.txt’,’w’);
> fprintf(fid,’%12.0f,%12.3f,%12.3f\n’,b);
> fclose(fid)
Running from an MFile

Open a new file under the File menu (choose “Mfile”).

Enter the Matlab commands in the same way that you would through the Command
window.
For example:
clear
for k = 1:10
x(k) = k;
y(k) = k^2;
end