MATH 353
Matlab 1

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. You should work through lab1 by typing in the Command Window the text that appears after the prompt (>>). 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

MATLAB allows you to assign numerical values to a variable. Type

>> a=2, b=1

>> c=a +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).

Learn how to use MATLAB's extensive help.

Recording your work. Diary files. Type

>>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. If you want to start recording again, enter >>diary lab1

A good comment like "This class is great!" can be written in the Command Window using the % sign, i.e.,

>>%This class is great!

Type >>diary off again and check the content of the file lab1. Make sure now that you know how to e-mail this file to yourself, or you know how to copy the file on a portable device.

Now a brief introduction to ploting. Type:

>> inc=pi/5
>> x=0:inc:2*pi
>> y=sin(x)
>> plot(x,y)

>> 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.

Downloading Files.

Open a web browser and go to http://www.math.udel.edu/~bacuta/s07/m353/Math353codes

Download the files Plot1.m, Plot2.m into your mywork directory. To download Plot1.m click on the Plot1.m link, and then click ``File'' and then ``Save As..''. It should give you a list of your directories. Choose mywork . If you work with Safari, do not append another extension.

Click on ``Current Directory'' (middle left 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''.

Learn how to modify, save, and re-execute (in the Command Window) the script file Plot1.m .

Create your own script file. 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'' (middle left of 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. To exit MATLAB type >> exit

Feel free to ask (many) questions.         SEE HOMEWORK #2.