Matlab_Session_3

Matlab_Session_3 - Matlab Tutorial Session 3 This tutorial...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Matlab Tutorial Session 3 This tutorial session covers the following topics 1. Functions in Matlab. 2. Specific input and output commands to interact with the user. 3. Some useful commands not covered previously: size , length , nan , inf , isempty , isnan , isinf . 4. Example programs – Newton Raphson, Bairstow’s method. Next tutorial will introduce how to create a datafile can be directly loaded in Tecplot. Review of session 2 One point was missed in both previous sessions – matlab distinguishes between uppercase and lowercase characters in variable names. E.g. M and m are different variable names. Variable names can be very long also (about 30 characters long) and can include alphabets, digits and underscore ( _ ). In matlab, either one may work at the command prompt directly, or write M-files in the editor ( edit command), save them with some suitable name (with extension .m ), and run them by typing the filename (excluding .m ) at command prompt. Matlab can only execute an M-file when it can find them in the current directory or its path ( path , addpath , cd , dir commands). There are two types of M-files – script files and functions . Script files are meant to execute a program (i.e., a set or sequence of matlab statements), and these are what were covered in session 2. This session covers functions. The for loop is just like the DO loop of Fortran. It is based upon the colon operator ( : ) and can handle real numbers also, e.g. for j = 0.8 : 0.02 : 1.2 . It is ended with an end keyword. Boolean conditions are evaluated as integers: 0 for false and non-zero for true. Logical operators such as > , < , >= , <= , == , ~= , , | , ~ are involved. if ( condition1) < statements > elseif (condition2) < statements > else < statements > end – this is the general syntax of decision making.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Conditional looping is performed using while : while (condition) < statements > end All variables reside on the workspace until cleared with the clear or clear all commands. The variables can be seen in the workspace browser window (to the immediate left of command window), or using who and whos commands. Matlab save and load commands can be used to easily save or read many variables simultaneously to / from files. These files have .mat extension and are called MAT files. However this file format is not useful for interacting with other softwares such as excel or tecplot . For this purpose, there are other commands such as dlmread , dlmwrite , xlsread etc, but these commands associate only one variable with one file. Full control over file input and output (such as that available in Fortran) is provided through more complex commands, but these can be discussed only in a separate tutorial. A figure window is created / selected using the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

Matlab_Session_3 - Matlab Tutorial Session 3 This tutorial...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online