Professional Documents
Culture Documents
Explore the use of the functions round, ceil, floor and fix for the values x =
0.3, x = 1/3, x = 0.5, x = 1/2, x = 1.65 and x = −1.34.
Matlab Solution :-
For round:-
>> round x=0.3
ans = 120 61 48 46 51
>> round x=1/3
ans = 120 61 49 47 51
>> round x=0.5
ans = 120 61 48 46 53
>> round x=1/2
ans = 120 61 49 47 50
>> round x=1.65
ans = 120 61 49 46 54 53
>> round x=-1.34
ans = 120 61 45 49 46 51 52
For ceil :-
>> ceil x=0.3
ans = 120 61 48 46 51
>> ceil x=1/3
ans = 120 61 49 47 51
>> ceil x=0.5
ans = 120 61 48 46 53
>> ceil x=1/2
ans = 120 61 49 47 50
>> ceil x=1.65
ans = 120 61 49 46 54 53
>> ceil x=-1.34
ans = 120 61 45 49 46 51 52
For Floor :-
>> floor x=0.3
ans = 120 61 48 46 51
>> floor x=1/3
ans = 120 61 49 47 51
>> floor x=0.5
ans = 120 61 48 46 53
>> floor x=1/2
ans = 120 61 49 47 50
>> floor x=1.65
ans = 120 61 49 46 54 53
>> floor x=-1.34
ans = 120 61 45 49 46 51 52
For fix:-
>> fix x=0.3
ans = 120 61 48 46 51
>> fix x=1/3
ans = 120 61 49 47 51
>> fix x=0.5
ans = 120 61 48 46 53
>> fix x=1/2
ans =120 61 49 47 50
>> fix x=1.65
ans = 120 61 49 46 54 53
>> fix x=-1.34
ans = 120 61 45 49 46 51 52
>> rem(3,3)
ans = 0
>> rem(3,4)
ans = 3
>> rem(4,-4)
ans = 0
>> rem(5,6)
ans = 5
For mod(x,y):-
>> format rat
>> mod (3,3)
ans = 0
>> mod(3,4)
ans = 3
>> mod(4,-4)
ans = 0
>> mod(4,6)
ans = 4
>> mod(5,6)
ans = 5
Matlab Solution :-
Values Of x:-
>> x = 1:0.1:2
x = Columns 1 through 11
1. y = x^3 + 3x^2 + 1
>> y = x.^3 + 3*x.^2 + 1
y = Columns 1 through 11
5.0000 5.9610 7.0480 8.2670 9.6240 11.1250 12.7760 14.5830 16.5520
18.6890 21.0000
2. a = sinx^2
>> a = sin(x).^2
a = Columns 1 through 11
3. b = (sinx)^2
>> b = (sin(x)).^2
b = Columns 1 through 11
d = 0.4390
6. e = cos x/1+sin x
>> e = cos(x)/(1 + sin(x))
e = 0.0328
7. f = 1/x + x^3/(x^4 + 5x sin x)
>> f = 1/x + x^3/(x^4 + 5x sin x)
f = Columns 1 through 11
Matlab Solution :-
>> x=3:0.01:5;
>> y = ((x)./(x)+(1)./(x.^2))
y = Columns 1 through 201
Matlab Solution :-
>> x = linspace(0,1,200);
>> g = x.^3+1;
>> h = x+2;
>> z = x.^2;
>> y = cos (x.*pi);
>> f = (y.*z)/(g.*h)
f = -0.0872
Matlab Solution :-
First Code:
>> x=-2:20:2;
>> c=[1 0 0 -1];
>> y=polyval(c,x);
>> plot(y,x)
Figure:
Second Code
>> x=-2:0.1:2;
>> c=[1 0 0 -1];
>> y=polyval(c,x);
>> plot(y,x)
Figure: