MATLAB is a very powerful and interactive software package for numerical computations. It is based upon matrices and m-files.
First, log on to your generic account {student} & {m4th4UD} . If you are unable to do that, please get a hold of me.
Open MATLAB. Work through lab1 by following all the bellow instructions. The text after the prompt (>>) represents a MATLAB command, and it should be typed in the Command Window. First, go to the home directory by typing (in the Command Window)
>> cd ~
Then type
>> mkdir mywork (or whatever you wish to name this directory)
and
>> cd mywork
MATLAB can be used as a CALCULATOR. Try:
>>2^10
>> ans/2^8
MATLAB allows you to assign numerical values to a variable. Type
>> a=2, b=1
>> c=a +b
>> c=a + 2*b
>> c=a + 2*b;
>> c
If one ends a command by semi-column, MATLAB does its work ``silently'', but everything is still there.
MATLAB outputs numbers in various formats. Type,
>> c = sqrt(2)
>>format long
>> c
>> c =100* c
>>format
>>c
>>help format
Learn how to use the Command History (UP and DOWN arrow keys). Repeatedly pressing the ``UP Arrow'' key will review the previous commands. To re-execute a command, press the ``return'' key. Once a command is recalled it might be changed by using the ``left arrow'' and the ``right arrow'' keys.
Learn how to use MATLAB's extensive help.
Use the search window to find information about the MATLAB: det ( from determinant) function. Read the Description of d= det(X).
Use the search window to find information about format. Read about ``format'' on the the right part of the Help window.
Demos: Go back to Help->Product Help. From the the right part of the Help window choose ->MATLAB ->Mathematics - Matrix Manipulation or, if you are NOT in Ewing 207 room, choose Getting Started with MATLAB Video
>>diary lab1
From this point on, everything that appears in the Command Window will also be recorded in the text file lab1. Type the following list of commands (each one of them at a new prompt >>).
pi, exp(1), help exp, help elfun, diary off
FIND the text file lab1, you just have created. Learn how to open it, and erase or add more text in this file.
Erase from your diary file the output of the command help elfun
Start recording again by entering >>diary lab1
Add to your diary file, by typing in the Command Window (not by opening the file with another editor) a comment like "This class is great!, or something like that..." . It can be done by using the % sign, i.e.,
>>%This class is great, ...!
Now, type again >>diary off , and check the content of the file lab1. Make sure that you know how to e-mail this file to yourself, or you know how to copy the file on a portable device.
>> inc=pi/5
>> x=0:inc:2*pi
>> y=sin(x)
>> plot(x,y)
Use the Command History (arrow keys) to type:
>> inc=pi/100
>> x=0:inc:2*pi;
>> y=sin(x);
>> plot(x,y)
Notice the difference in the two plots.
You can save the plot as a .fig file by clicking on ``File'' and then on ''Save As..". Make sure that you save the file in your working directory.
You can print the plot by clicking on ``File'' and then on ``Print'' and then click on ``Print.'' DO NOT DO THIS NOW. For now, click ``Cancel.'' Print it at your convenience some other time.
Open a web browser and go to http://www.math.udel.edu/~bacuta/M353/MatlabCodes.html
Click on ``Current Directory'' (left or right of the MATLAB window) an then, type in the Command Window:
>> ls
>> what
Do you get a different list of files? Why?
Type: >>Plot1
Type: >> help Plot1
Open the file Plot1.m in the MATLAB editor. In the MATLAB window, click ``File'' and then ``Open..'' It should give you the list of the files in your mywork directory. Choose Plot1.m and click ``Open''.
Modify the value of n to n=410 , save, and re-execute (in the Command Window) the script file Plot1.m .
Click ``File'' and then ``New -M-File''
Type in the new window (MATLAB's editor):
% This is my first script file. It plots the sin function on [ 0, 2*pi].
inc=pi/100;
x=0:inc:2*pi;
y=sin(x);
plot(x,y)
Click (use the editor's menu) ``File'' and then ``Save As''. Modify the default name untitled.m to, say my_plot.m . Make sure that you save the file in your working directory.
In the MATLAB Command Window type:
>> help my_plot
>> my_plot
Before you exit, click on ``Workspace'' ( find it on the MATLAB window) and notice the content of your current "Workspace". Then, type in the Command Window:
>> x=8
>>y=[1 2]
>>z=[ 1 2; 3 4]
Keep one eye on the "Workspace" window, and type
>> who
>> whos
>> clear x
>> z, y, x
>> clear
Make sure that you know exactly what each of the above commands does.