help Square
Function that returns the square of its input argument.
Input: x: real variable
Output: xSqr: square of x
% special numbers
1/0
ans =
Inf
0/0
ans =
NaN
4/3
ans =
1.3333
format long
4/3
ans =
1.333333333333333
(4/3)-1
ans =
0.333333333333333
ans*3-1
ans =
-2.220446049250313e-16
(4000/3)-1000
ans =
3.333333333333333e+02
ans*3-1000
ans =
-2.273736754432321e-13
1.1-1
ans =
0.100000000000000
ans*10-1
ans =
8.881784197001252e-16
sin(10*pi)
ans =
-1.224646799147353e-15
sin(10000000000000000*pi)
ans =
-0.375212890012334
% precedence:
% ^
% * /
% + -
2+3*4
ans =
14
2+(3*4)
ans =
14
(2+3)*4
ans =
20
12/2*3
ans =
18
12/(2*3)
ans =
2
x=1
x =
1
y=2
y =
2
x=y;
y=x;
x
x =
2
y
y =
2
xold=x
xold =
2
x=y
x =
2
y=xold
y =
2
x=1
x =
1
y=2
y =
2
xold=x
xold =
1
x=y
x =
2
y=xold
y =
1
pi
ans =
3.141592653589793
pi=3.2
pi =
3.200000000000000
pi
pi =
3.200000000000000
clear pi
pi
ans =
3.141592653589793
trysqr
Start of trysqr
ans =
9
y =
4
ans =
16
trysqr
Start of trysqr
clear
if system_dependent('IsDebugMode')==1, dbstep in; end
if system_dependent('IsDebugMode')==1, dbstep; end
if system_dependent('IsDebugMode')==1, dbstep; end
if system_dependent('IsDebugMode')==1, dbstep; end
if system_dependent('IsDebugMode')==1, dbstep; end
ans =
9
if system_dependent('IsDebugMode')==1, dbstep; end
y =
4
if system_dependent('IsDebugMode')==1, dbstep in; end
if system_dependent('IsDebugMode')==1, dbstep; end
if system_dependent('IsDebugMode')==1, dbstep; end
if system_dependent('IsDebugMode')==1, dbstep; end
if system_dependent('IsDebugMode')==1, dbstep; end
ans =
16
whos y
Name Size Bytes Class Attributes
y 1x1 8 double
list = [1 2 4 9 16]
list =
1 2 4 9 16
sqrt(list)
ans =
Columns 1 through 2
1.000000000000000 1.414213562373095
Columns 3 through 4
2.000000000000000 3.000000000000000
Column 5
4.000000000000000
list=[0 30 45 60 90]
list =
0 30 45 60 90
sinlist=sind(list)
sinlist =
Columns 1 through 2
0 0.500000000000000
Columns 3 through 4
0.707106781186547 0.866025403784439
Column 5
1.000000000000000
tanlist=tand(list)
tanlist =
Columns 1 through 2
0 0.577350269189626
Columns 3 through 4
1.000000000000000 1.732050807568878
Column 5
Inf
[1 2 3 4 5 6 7 8 9 10]
ans =
Columns 1 through 7
1 2 3 4 5 6 7
Columns 8 through 10
8 9 10
1:10
ans =
Columns 1 through 7
1 2 3 4 5 6 7
Columns 8 through 10
8 9 10
2:5
ans =
2 3 4 5
2:2:30
ans =
Columns 1 through 7
2 4 6 8 10 12 14
Columns 8 through 14
16 18 20 22 24 26 28
Column 15
30
30:-2:4
ans =
Columns 1 through 7
30 28 26 24 22 20 18
Columns 8 through 14
16 14 12 10 8 6 4
30:-2:-4
ans =
Columns 1 through 7
30 28 26 24 22 20 18
Columns 8 through 14
16 14 12 10 8 6 4
Columns 15 through 18
2 0 -2 -4
list = [1 2 4 9 16]
list =
1 2 4 9 16
sqrt(list)
ans =
Columns 1 through 2
1.000000000000000 1.414213562373095
Columns 3 through 4
2.000000000000000 3.000000000000000
Column 5
4.000000000000000
sqr(list)
{Error using *
Incorrect dimensions for matrix
multiplication. Check that the number of
columns in the first matrix matches the
number of rows in the second matrix. To
perform elementwise multiplication, use
'.*'.
Error in sqr (line 3)
x2=x*x;}
sqr(list)
ans =
1 4 16 81 256
sqr(list)
{Error using ^
Incorrect dimensions for raising a matrix
to a power. Check that the matrix is square
and the power is a scalar. To perform
elementwise matrix powers, use '.^'.
Error in sqr (line 3)
x2=x^2;}
sqr(list)
ans =
1 4 16 81 256