# Uka PExer02

```Name:
Uka, Johannie S.
Numerical Methods
PExer02
Task I. For row vector x with values from 1 to 2 in steps of 0.25, evaluate the following mathematical expressions
and supply the correct MatLab command and its result.
Mathematical
Expression
Matlab Command
x = [1:.25:2];
y = x3 + 3x2 + 1
y = x.^3 + 3*x.^2 + 1
y = sin x2
x = [1:.25:2];
y = sin(x.^2)
3.
y = (sin x)2
x = [1:.25:2];
y = sin(x).^2
4.
y = sin 2x + x cos 4x
x = [1:.25:2];
y = sin(2.*x) + x.*cos(4.*x)
5.
y = x/(x2 + 1)
x = [1:.25:2];
y = x./(x.*2 + 1)
6.
y=
7.
y=
1.
8.
9.
cos x
1  sin x
1
x3
 4
x x  5 x sin x
x
y=
x  x12
y=
1
1 3
 2 
3
x
x
x
10. y = tan-1 (x)
Result
y = 1&times;5
5.0000
7.6406
11.1250
15.5469
21.0000
y = 1&times;5
0.8415
1.0000
0.7781
0.0790
0.7568
y = 1&times;5
0.7081
0.9006
0.9950
0.9682
0.8268
y = 1&times;5
0.2557
0.9530
1.5814
0.9685
1.0478
y = 1&times;5
0.3333
0.3571
0.3750
0.3889
0.4000
y = 1&times;5
0.2934
0.1618
0.0354
-0.0898
0.2180
y = 1&times;5
6.2074
7.5312
8.8145
9.7527
10.0930
y = 1&times;5
0.5000
0.6614
0.7714
0.8428
0.8889
y = 1&times;5
5.0000
3.5520
2.7407
2.2274
1.8750
y = 1&times;5
0.7854
0.8961
0.9828
1.0517
1.1071
x = [1:.25:2];
y = cos(x)./(1+ sin(x))
x = [1:.25:2];
y = (1./x) + (x.^3)./x.^4+5.*x.*sin(x)
x = [1:.25:2];
y = x./(x+(1./(x.^2)))
x = [1:.25:2];
y = (1./(x.^3))+(1./(x.^2))+(3./(x))
x = [1:.25:2];
y = atan(x)
Task II. Explore the use of functions round, ceil, floor and fix for each value of x. Write down the result of each
function in its specified column.
11.
12.
13.
14.
15.
x
0.3
1/3
0.5
2/7
1.65
round( )
0
0
1
0
2
ceil( )
1
1
1
1
2
floor( )
0
0
0
0
1
fix( )
0
0
0
0
1
16.
17.
18.
19.
20.
1/2
-1.34
5/9
4.95
2.85
1
-1
1
5
3
1
-1
1
5
3
0
-2
0
4
2
0
-1
0
4
2
Task III. Create a Matlab function named xrcff( ) that would do the following:
a) Assign the values of x as indicated in Task II
b) Perform the functions round, ceil, floor, and fix for each value of x
c) Display the table of values with the following data: x, round(x), ceil(x), floor(x), and fix(x) formatted
into two decimal digits. Make sure to include appropriate heading on your table.
Name:
Uka, Johannie S.
Numerical Methods
PExer02
Code:
function xrc = xrcff(x)
x = [.3 1/3 .5 2/7 1.65 1/2 -1.34 5/9 4.95 2.85]
fprintf('x\t\t\t round()\t ceil()\t\t floor()\t fix()\t\n')
for i = 1:length(x);
fprintf('%.2f\t\t %.2f\t\t %.2f\t\t %.2f\t\t %.2f\t \n', x(i), round(x(i)), ceil(x(i)),
floor(x(i)), fix(x(i)))
end
end
Classroom License -- for classroom instructional use only.
&gt;&gt; xrcff
x=
Columns 1 through 9
0.3000
0.3333
0.5000
0.2857
1.6500
0.5000 -1.3400
Column 10
2.8500
x
0.30
0.33
0.50
0.29
1.65
0.50
-1.34
0.56
4.95
2.85
&gt;&gt;
round()
0.00
0.00
1.00
0.00
2.00
1.00
-1.00
1.00
5.00
3.00
ceil()
1.00
1.00
1.00
1.00
2.00
1.00
-1.00
1.00
5.00
3.00
floor()
0.00
0.00
0.00
0.00
1.00
0.00
-2.00
0.00
4.00
2.00
fix()
0.00
0.00
0.00
0.00
1.00
0.00
-1.00
0.00
4.00
2.00
0.5556
4.9500
```