130 likes | 423 Vues
Getting Started with MATLAB ( part 3 ). Algebra, Trig The keyword ans Clean up and suppress output: finalizing the software’s presentation. 1. 1. Algebra. Preceden ce rules apply: 2+3 <enter> 2-6 <enter> 2*3 <enter> 7/3.5 <enter>. 2+3*3 <enter> (2+3)*3 <enter> 5^2 <enter>
E N D
Getting Startedwith MATLAB (part 3) Algebra, Trig The keyword ans Clean up and suppress output: finalizing the software’s presentation 1
1. Algebra • Precedence rules apply: • 2+3 <enter> • 2-6 <enter> • 2*3 <enter> • 7/3.5 <enter> • 2+3*3 <enter> • (2+3)*3 <enter> • 5^2 <enter> • i^2 <enter>
2. Trigonometry • Why does sin(30) give a “wrong” answer? _________________________
2. Trigonometry • Common functions • sin(), cos(), tan(), sind(), cosd(), tand(), • asin(), acos(), atan(), asind(), acosd(), atand() • exp(), sqrt(), log(), log10() • abs(), round() 4
3. The keyword ans • Next question: What is ans ? ____________
4. Polishing the final product • clear <enter>typed inside the command window • Will delete all the variables in the Workspace this time. There is no going back. This cleans up every variable from memory. (No more little yellow boxes in the Workspace) • clc <enter> typed inside the command window • Will completely erase the content of the command window. It does not affect the Workspace - the variables still exist and can be used.
“Suppressing” the output • Hiding intermediate results, or even initial variables No semi-colons…
“Suppressing” the output • Second version, with semi-colons Using a semicolon on these lines “suppresses the output”. In other words, it does not showthe result of the command. But… did the commands do anything?
“Suppressing” the output • Still second version (with semi-colons) The variables ARE CREATED, and commands ARE executed!
“Suppressing” the output • Since the result does not show up automatically in the command window, to **recall** (i.e. show again) the variable: • type area <enter>in the command window
Wrapping Up • Algebra reminders • Order of Operations: • Parentheses • Exponent • Multiplication and Division are the same precedence • Addition and Subtraction are the same precedence • Trigonometry • MATLAB standard trig functions use radians by default e.g. sin() uses radians; sind()uses degrees • Suppressing the output: • Use a semi-colon at the end of calculations