{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Basic Features

# Basic Features - Chapter 2 Basic Features 2.1 Simple Math...

This preview shows pages 1–6. Sign up to view the full content.

Chapter 2 Basic Features 2.1 Simple Math The MATLAB Command window is the primary means for interacting with MATLAB. When the Command window is active, statements are entered which can be executed immediately. For example, simple mathematical calculations can be performed and the results displayed. The results of each calculation are stored in the default MATLAB variable named ' ans ' which retains its value until its changed. Example 2.1.1 100+5*12 100/5 + 6^2 2*ans 2*(25+(3*exp(1))) ans = 160 ans = 56 ans = 112 ans = 66.3097 Alternatively, the results can be assigned to user defined MATLAB variables. Example 2.1.2 t_initial=4; t_final=12; t_elapsed=t_final-t_initial rate=5 distance=rate*(t_elapsed) t_elapsed = 8 rate = 5 distance = 40 Note the semicolon suppresses displaying the result of executing a MATLAB command. 1

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

View Full Document
2.2 The MATLAB Workspace During a MATLAB session, the issued commands and the variables resulting from those commands are saved in the MATLAB workspace. The numerical values asssigned to variables are stored there and easily accessed by entering the variables' names at the MATLAB prompt. Example 2.2.1 l=3; w=12; A=l*w; A l,w,A A = 36 l = 3 w = 12 A = 36 The ' who ' command results in a list of the current MATLAB workspace variables. Example 2.2.3 who Your variables are: A distance rate t_final w ans l t_elapsed t_initial 2
2.3 About Variables MATLAB variable names must be a single word, no spaces, no punctuation characters, start with a letter and no more than 31 recognized characters. Several names have special meaning and should not be used for other purposes. For example, ' ans ', Default variable name used for results ' pi ', The value of π ' i' or ' j ', -1 ' eps ', Smallest number that can be added to one resulting in a number larger than one in the computer ' inf ', ' NaN' , Not a number, e.g. 0/0 etc. Example 2.3.1 radius_of_circle_5 = 4 Area=pi*radius_of_circle_5^2 radius_of_circle_5 = 4 Area = 50.2655 eps ans = 2.2204e-016 x=3+2*j y=4-5i z=x+y x = 3.0000 + 2.0000i y = 4.0000 - 5.0000i z = 7.0000 - 3.0000i a=1 b=2 c=b/(b-2*a) d=(a*b-2) /(b-2*a) a = 1 3

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

View Full Document
b = 2 Warning: Divide by zero. c = Inf Warning: Divide by zero. d = NaN 4
2.4 Comments, Punctuation, and Aborting Execution MATLAB ignores all text following a % symbol to allow commenting. Example 2.4.1 int_nominal=0.08; % Loan interest rate (per year) int_monthly=int_nominal/12; % Loan interest rate (per month) P=270000; % Loan Amount n_years=30; % Duration of loan (in years) n_months=n_years*12; % Duration of loan (in months) x=(1+int_monthly)^n_months; A=P*(int_monthly*x)/(x-1) % Monthly installment to repay loan A = 1.9812e+003 More than one command can appear on the same line if they are separated by a

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

Basic Features - Chapter 2 Basic Features 2.1 Simple Math...

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

View Full Document
Ask a homework question - tutors are online