SUNY Geneseo Department of Mathematics
Wednesday, September 2
Math 230 01
Fall 2015
Prof. Doug Baldwin
clc
- clear commandsclear
- erase variablesdiary
- record sessionformat long
(format short
) - numeric precision>> format compact
>> % What happens if you rename something built in to Matlab?
>> sin( pi/2 )
ans =
1
>> sin = 0
sin =
0
>> sin( pi/2 )
{Subscript indices must either be real positive
integers or logicals.}
>> % 2x + 1
>> x = 2
x =
2
>> 2x + 1
2x + 1
|
{Error: Unexpected MATLAB expression.
}
>> 2*x + 1
ans =
5
>> % x squared + 1
>> x^2 + 1
ans =
5
>> x = 4
x =
4
>> x^2 + 1
ans =
17
>> x * x + 1
ans =
17
>> % square root
>> x ^ 1/2
ans =
2
>> x = 36
x =
36
>> x ^ 1/2
ans =
18
>> x ^ (1/2)
ans =
6
>> x ^ 0.5
ans =
6
>> sqrt( x )
ans =
6
>> % Pythagorean Theorem: c = square root of a squared + b squared
>> c = sqrt( a^2 + b^2 )
{Undefined function or variable 'a'.}
>> a = 3;
>> b =4;
>> c = sqrt( a^2 + b^2 )
c =
5