plugin-math245lab01

# plugin-math245lab01 - Math245 Lab set#1 Spring 2009...

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

Math245 Lab set #1 Spring 2009 Introduction to Matlab Basics 1 Matlab desktop 1. Variable assignment and arithmetic operations You can create any variables by assigning values to it in the form: (your variable name ) = (expression) General rule here is the notation " = " is NOT the same as the mathematical equality. " = " is called assignment operator. Your specified (expression) in rhs is assigned to (your specified variable name). Like using your calculators, you can do arithmetic operations by using arithmetic operators, i.e., + : addition, - : subtraction, * : multiplication, / : division, and ^ : exponentation. You can also use standard mathematical functions (e.g., sin, cos, exp, tanh, etc.) provided in Matlab package. Example 1: a = 1.0 a = 1 Page 1 Command window (you put matlab command in here) Command history window (shows history of command) File list of current working directory Current working directory

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

View Full Document
Spring 2009 a = a + 1 % This statement assigns "a+1" to "a". ("a" is renewed by the value "a+1") a = 2 pi % π is already defined in Matlab package. ans = 3.1416 c = cos(a*pi)^2 + exp(a/2.0) – 1.0 % exp(a/2) means / 2 a e c = 2.7183 For more digits, use format or vpa command. format long c = 2.71828182845905 Vpa(c,30) ans = 2.71828182845904553488480814849 So far we have created variables a, c and ans in Matlab work space (computer memory). To check what variables we have in the work space, just type ‘who’ or ‘whos’. who Your variables are: a ans c whos Name Size Bytes Class a 1x1 8 double array ans 1x1 8 double array c 1x1 8 double array Grand total is 3 elements using 24 bytes To clear all the variables in the work space you simply put ‘clear’ command. clear Then after putting ‘who’ command, no variables are listed, because we cleared all variables already. who
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 06/01/2009 for the course MATH 245 taught by Professor Alexander during the Spring '07 term at USC.

### Page1 / 8

plugin-math245lab01 - Math245 Lab set#1 Spring 2009...

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

View Full Document
Ask a homework question - tutors are online