EXPERIMENT 4
AIM:
Evaluating a given expression and rounding it to the nearest integer value using Round, Floor,
Ceil and Fix functions; Also, generating and Plots of
(A) Trigonometric Functions - sin(t), cos(t), tan(t), sec(t), cosec(t) and cot(t) for a given duration, ‘t’.
(B) Logarithmic and other Functions – log(A), log10(A), Square root of A, Real nth root of A.
SOFTWARE REQURIED:
MATLAB R2015a.
THEORY:
FUNCTIONS USED:
▪ Round (): Round to nearest decimal or integer Y = round(X) rounds each element of X to the
nearest integer. In the case of a tie, where an element has a fractional part of exactly 0.5,
the round function rounds away from zero to the integer with larger magnitude.
1. Y = round(X,N) rounds to N digits:
2. N > 0 : round to N digits to the right of the decimal point.
3. N = 0 : round to the nearest integer.
4. N < 0 : round to N digits to the left of the decimal point.
▪ Floor (): Round toward negative infinity Y = floor(X) rounds each element of X to the nearest
integer less than or equal to that element.
1. Y = floor(t) rounds each element of the duration array t to the nearest number of seconds
less than or equal to that element.
2. Y = floor(t,unit) rounds each element of t to the nearest number of the specified unit of
time less than or equal to that element.
▪ Ceil (): Round toward positive infinity Y = ceil(X) rounds each element of X to the nearest
integer greater than or equal to that element.
1. Y = ceil(t) rounds each element of the duration array t to the nearest number of seconds
greater than or equal to that element.
2. Y = ceil(t,unit) rounds each element of t to the nearest number of the specified unit of time
greater than or equal to that element.
▪ Fix (): Round toward zero Y = fix(X) rounds each element of X to the nearest integer toward
zero. For positive X , the behavior of fix is the same as floor. For negative X, the behavior
of fix is the same as ceil.
▪ LOGARITHMIC & OTHER FUNCTIONS
CODE:
a=1:1:50 legend('log10x')
b=log(a) grid on
c=log10(a) subplot(2,2,3)
d=sqrt(a) plot(a,d);
e=nthroot(a,5) xlabel('x')
subplot(2,2,1) ylabel('sqrtx')
plot(a,b); title('sqrtx')
xlabel('logx') legend('sqrtx')
ylabel('x') grid on
title('logx') subplot(2,2,4)
legend('logx') plot(a,e);
grid on xlabel('x')
subplot(2,2,2) ylabel('nthroot')
plot(a,c); title('nthroot')
xlabel('x') legend('nthroot')
ylabel('log10x') grid on
title('log10x')
EXPERIMENT 5
AIM:
Creating a vector X with elements, Xn = (-1)n+1/(2n-1) and Adding up 100 elements of the vector,
X; And, plotting the functions, x, x3, ex, exp(x2) over the interval 0 < x < 4 (by choosing appropriate
mesh values for x to obtain smooth curves), on a Rectangular Plot.
SOFTWARE REQURIED:
MATLAB R2015a.
THEORY:
POWER
▪ C = A.^B raises each element of A to the corresponding powers in B. The sizes of A and B
must
be the same or be compatible.
▪ If the sizes of A and B are compatible, then the two arrays implicitly expand to match each
other. For example, if one of A or B is a scalar, then the scalar is combined with each element
of the other array. Also, vectors with different orientations (one row vector and one column
vector) implicitly expand to form a matrix.
CODE:
for N=1:100 xlabel('x')
x(N) = (-1)^(N+1)/(2*N-1) ylabel('x^2')
end title('x^2')
Y=x grid on
sum(x) figure,plot(R)
Z = Y.^3 xlabel('x')
A = Y.^2 ylabel('exp(x^3)')
Q = exp(Z) title('exp(x^3)')
R = exp(A) grid on
figure,plot(Z) figure,plot(Q)
xlabel('x') xlabel('x')
ylabel('x^3') ylabel('exp(x^2)')
title('x^3') title('exp(x^2)')
grid on grid on
figure,plot(A) subplot(2,2,1)
plot(Z) plot(R)
xlabel('x') xlabel('x')
ylabel('x^3') ylabel('exp(x^3)')
title('x^3') title('exp(x^3)')
grid on grid on
subplot(2,2,2) subplot(2,2,4)
plot(A) plot(Q)
xlabel('x') xlabel('x')
ylabel('x^2') ylabel('exp(x^2)')
title('x^2') title('exp(x^2)')
grid on grid on
subplot(2,2,3)