Back to Homepage
Quick Links
Mathematics Department
REU Program
Matlab Tutorial
Latex Turtorial
Not So Short Guide to Latex (pdf)
How to write mathematics (pdf)
Templates
Euler Integration (m-file)
Phase Portraits (m-file)
How to plot phase portraits (pdf)
Report Template (txt)
Report Template (pdf)
Report Template Figure 1 (pdf)
Report Template Figure 2 (pdf)
Sample Report
Sample Report (txt)
Sample Report (pdf)
Sample Report Figure 1 (eps)
Sample Report Figure 2 (eps)
BSLC Lab Instructions
Opening and using Matlab
Opening and using MikTeX
Application and Computations Labs
Project Options for Labs
|
Opening MATLAB
Under the "Start" menu go to "Programs" then "Applications" then "MATLAB R2010a". Malab will load (be patient, it may take some time).
Using MATLAB from the control prompt
You should be looking at an open matlab window. Type the following:
>> a = pi;
>> x = (1:2:10);
You have just named the scalar "a" and assigned it the value "pi" and the row vector "x" and assigned it the values starting at 1 and incremented by 2 until 10. Type the name of the element (without simicolons) to see the values of these variables. The semicolon "suppresses" the output from showing up on the screen. For example
>> x
Creating and using m-files
To create an m-file, go to "File", "New", "Script". This will cause a new window (an editor) to pop-up. Create a script by tying the following into the editor
%We want to solve Ax = y --note using a % symbol tells matlab that this line is a comment, not a command
y = (1:1:4);
A = [1 1 1 1; 2 3 4 5; 2 1 2 2; 1 1 1 0];
%check det(A) not zero
if(det(A) ~=0 )
B = inv(A);
x = B*transpose(y)
end
Then, in the editor window, go to "File", "Save As...", and save this file as "ex1.m" to "My Documents". To run the m-file, either click on the green "play" button, or return to the matlab command prompt and type:
>> ex1
Exporting Figure
First create a figure by typing the following:
>> x = (-10:0.1:20);
>> y = pi*x.^2-x.^3;
>> z = -x.^2+3*ones(size(x));
>> figure(1)
>> clf
>> plot(x,y,'r')
>> hold on
>> plot(x,z,'b')
>> legend('y vs. x', 'z vs. x')
>> xlabel('x-axis')
>> ylabel('yz-axis')
Note, "clf" clears the figure, while "hold on" prevents the figure from being cleared. To export the figure, in the figure window, go to "File", then "Export Setup..." In this menue you can change various aspect of the appearance. For the time being, just click on the "Export..." button on the right. Another widow will pop up asking you to save the file. Save it as "fig1.pdf" as a pdf file in "My Documents." Once it is saved, click "OK" in the "Export Setup" box.
|
|