Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB Introduction Dr. Theodore Cleveland University of Houston

Similar presentations


Presentation on theme: "MATLAB Introduction Dr. Theodore Cleveland University of Houston"— Presentation transcript:

1 MATLAB Introduction Dr. Theodore Cleveland University of Houston
CIVE 1331 – Computing for Engineers Lecture 016 NEXT LECTURE: Powerpoint, EXCLE

2 Mat Lab Environment MatLab – Getting Going – Parallels with FORTRAN and EXCEL………………………………..3 Assign Values………………………………………5 Saving Your Work……………………………………..7 Reading data from an ASCII file ……………….10 Matrix Operations ……………………………………14 Plotting …………………………………………………..17 Generating Scripts (Programs )………………….21 Programming the Problem…………………..24 Change PATH variable and attempt to run the code ……………………………………..25

3 MatLab – Getting Going – Parallels with FORTRAN and EXCEL
Assumptions: You have tested your account and can invoke some version of MatLab. Release12 and Release13 are currently available for this class. Use R13 unless it messes up, then use R12. I demonstrated R12 in lecture.

4 MatLab – Getting Going – Parallels with FORTRAN and EXCEL
Variables: Variables have names and contain values. Matlab considers all variables to be arrays; scalars are 1 x 1 arrays.

5 MatLab – Getting Going – Parallels with FORTRAN and EXCEL
Assign values: To assign a value simply use FORTRAN like syntax; X=3.2; y=7.5 Matrix2x2=[[1,2];[3,4]] The delimiters “[“ and “]” enclose lists. The delimiter ; separates lists (it also suppresses output when used at end of a command). The matrix is a list of lists. Technically X and Y could have been entered as X=[3.2] ; y=[7.5]

6 MatLab – Getting Going – Parallels with FORTRAN and EXCEL
Figure 1. Assigning Values

7 Saving Your Work To save your work you must point the program to a directory where you have write privileges, such as your H: directory in the ECC; and ZipDrive; a FloppyDrive; a USB drive; or even the C:\WORK or C:\TEMP directory. To change where the program reads and writes data files use either the Current Directory winder in the program or enter the command line disk operations commands: dir; delete, cd, path. (See pg 19 of the text).

8 Saving Your Work The next two figures illustrate both approaches
Figure 3. Setting directory using commands.

9 Saving Your Work Now to save the work, simply type the save command or choose save using the File/Save or File/SaveAs Figure 4. Save command and file name (lecture010)

10 Reading Data From an ASCII File
Suppose we have the following ASCII files: Figure 5. amat.dat contents

11 Reading Data From an ASCII File
Then we can read these data into the MatLab program using the load command. Figure 6. rhs.dat

12 Reading Data From an ASCII File
Figure 7. Loading data into the program.

13 Reading Data From an ASCII File
We can also write to files (see page 24 and 25 of the text). These activities are equivalent to the FORTRAN read(unit,fmt) var_list and write (unit,fmt) var_list structures we studied earlier.

14 Plotting Suppose we want to plot the y=Bessel(0,x) for x = 0,5,0.2 (FORTRAN like syntax). In Matlab we simply construct two vectors then plot them. Figure 9. Setting up the plot vectors.

15 Plotting Figure 10. Resulting Plot

16 Plotting Now recall in Week 3 (and in labs) we got nicked for leaving labels off the graphics. To add labels we simply instruct the plotting tool to include labels (either in the command line, or after-the-fact in the plot window).

17 Plotting Read pages 44-51 for more on plotting.
Figure 11. Improved plot image Read pages for more on plotting.


Download ppt "MATLAB Introduction Dr. Theodore Cleveland University of Houston"

Similar presentations


Ads by Google