{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L2_basics_stud 2

# L2_basics_stud 2 - CGN 3421 Computer Methods Gurley Lecture...

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

CGN 3421 - Computer Methods Gurley Lecture 2 MATLAB basics page 9 of 15 Lecture 2 MATLAB basics Common tools: % and ; % indicates a comment, not a command to be executed MATLAB ignores comments. % can be placed at the end of an executable line to comment on that line >> weight=input(‘give weight’); %getting weight a ; following an assignment will suppress display of the command result. ; signals the end of a single command, and can be used to separate multiple sequential statements on the same line. >> density = 1.25; diameter = 10.2; Operators + Addition - Subtraction * Multiplication / Division ^ Power ' Complex conjugate transpose (swaps columns and rows) ( ) Specify evaluation order Order of Operations ( ) ^ highest level, first priority * / next priority level + - last operations to be performed >> y = 2; x = 3 * y^2 Ans: 12 >> y = 2; x = (3*y)^2 Ans: 36 >> y = 2; x = 3 * y + 2 Ans: 8 >> z = 3*6+6*2/4 Ans: 21 >> x = 5^2/2 Ans: 12.5

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

View Full Document
CGN 3421 - Computer Methods Gurley Lecture 2 MATLAB basics page 10 of 15 Order of Operations Example Express the quadratic formula in MATLAB Look at the following expressions. Identify which one will properly express the above equation. For the ones that don’t work, specify all the reasons it won’t work. >> x = -B + sqrt B^2 - 4*A*C / 2A % ??? >> x = -B + (B*B - 4*A*C)^(0.5)/2*A % ???
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

L2_basics_stud 2 - CGN 3421 Computer Methods Gurley Lecture...

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

View Full Document
Ask a homework question - tutors are online