Sunteți pe pagina 1din 6

EXPERIMENT NO.

AIM: Evaluating a given expression and rounding it to the nearest integer


value round, floor, ceil, and fix functions. ; also generating and plots of (A)
trigonometric functions- sin(t), cos(t), tan(t), cosec(t), sec(t) and cot(t) for a
given function, t. (B). logarithmic and other functions log(A), log10(A),
square root of A, real nth root of A.

TOOL USED: MATLAB 7.0


THEORY:
1. Round

Round to nearest decimal or integer


Y = round(X)
Y = round(X,N)

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.

2. Ceil

Round toward positive infinity


Y = ceil(X)
Y = ceil(t)

Y = ceil(X) rounds each element of X to the nearest integer greater than or equal
to that element.
Y = ceil(t) rounds each element of the duration array t to the nearest number of
seconds greater than or equal to that element.

3. Sin

Sine of argument in degrees


Y = sin(X)
Y = sin(X) returns the sine of the elements in X, which are expressed in
degrees.

4. Cos

Cosine of argument in degrees


Y = cos(X)
Y = cos(X) returns the cosine of the elements of X, which are expressed in
degrees.

5. Tan

Tangent of argument in degrees


Y = tan(X)
Y = tan(X) returns the tangent of the elements of X, which are expressed in
degrees.

6. Csc

Cosecant of argument in degrees


Y = csc(X)
Y = csc(X) returns the cosecant of the elements of X, which are expressed in
degrees.

7. Sec

Secant of argument in degrees


Y = sec(X)
Y = sec(X) returns the secant of the elements of X, which are expressed in
degrees.

8. Cot

Cotangent of argument in degrees


Y = cot(X)
Y = cot(X) returns the cotangent of the elements of X, which are expressed in
degrees.

9. Log

Natural logarithm
Y = log(X)

Y = log(X) returns the natural logarithm ln(x) of each element in array X.


The log function's domain includes negative and complex numbers, which can
lead to unexpected results if used unintentionally.

10. Sqrt

Square root
B = sqrt(X)

B = sqrt(X) returns the square root of each element of the array X. For the
elements of X that are negative or complex, sqrt(X) produces complex results.
11. nthroot

Real nth root of real numbers


Y = nthroot(X,N)

Y = nthroot(X,N) returns the real nth root of the elements of X.


Both X and N must be real scalars or arrays of the same size.

OUTPUT
>> A=rand(4,4)
A=
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
>> B=round(A)
B=
1 1 1 1
1 0 1 0
0 0 0 1
1 1 1 0
>> C=floor(A)
C=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> D=ceil(A)
D=
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
>> E=fix(A)
E=
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
>> F=randn(4,4)
F=
-0.1241 0.6715 0.4889 0.2939
1.4897 -1.2075 1.0347 -0.7873
1.4090 0.7172 0.7269 0.8884
1.4172 1.6302 -0.3034 -1.1471
>> G=floor(F)
G=
-1 0 0 0
1 -2 1 -1
1 0 0 0
1 1 -1 -2
>> H=ceil(F)
H=
0 1 1 1
2 -1 2 0
2 1 1 1
2 2 0 -1
>> I=fix(F)
I=
0 0 0 0
1 -1 1 0
1 0 0 0
1 1 0 -1

>> plot(fun)
>> a
a= 2
>> w
w =314.1593
>> t=0:0.01:100;
>> fun=a*sin(w*t);
>> plot(fun)
>> plot(t,fun)
>> t=0:0.1:100;
>> fun=a*sin(w*t);
>> plot(fun)
>> plot(fun,t)
>> t=0:0.001:100;
>> fun=a*sin(w*t);
>> plot(fun)
>> t=0:0.001:1;
>> fun=a*sin(w*t);
>> plot(t,fun)
>> fun=a*sin(w*t);
>> fun=a*cos(w*t);
>> plot(t,fun)
>> subplot(2,2,1)
>> subplot(2,2,1);plot(t,fun)
>> hold;
Current plot held
>> subplot(2,2,1);plot(t,fun)
>> hold
Current plot held
>> subplot(2,2,2);plot(t,fun)
>> y=a*cos(w*t);
>> subplot(2,2,1);plot(t,y)
>> hold
Current plot held
>> subplot(2,2,2);plot(t,fun)
>> z=a*tan(w*t);
>> hold
Current plot held
>> subplot(2,2,3);plot(t,z)
>> subplot(3,2,1);plot(t,y)
>> hold
Current plot held
>> subplot(3,2,2);plot(t,fun)
>> hold
Current plot held
>> subplot(3,2,3);plot(t,z)
>> hold
Current plot held
>> p=1./(a*sin(w*t));
>> subplot(3,2,4);plot(t,p)
>> hold
Current plot held
>> q=1./(a*cos(w*t));
>> subplot(3,2,5);plot(t,q)
>> r=1./(a*tan(w*t));
>> subplot(3,2,6);plot(t,r)
>> N=rand(3,3)

N=
0.2769 0.8235 0.9502
0.0462 0.6948 0.0344
0.0971 0.3171 0.4387
>> J=log(N)
J=
-1.2840 -0.1942 -0.0511
-3.0754 -0.3641 -3.3684
-2.3317 -1.1485 -0.8238
>> K=log10(N)
K=
-0.5576 -0.0844 -0.0222
-1.3356 -0.1581 -1.4629
-1.0126 -0.4988 -0.3578
>> f=1:0.001:100;
>> fun1=log(f);
>> plot(f,fun1)
>> plot(f,fun1)
>> subplot(1,2,1);plot(f,fun1)
>> hold
Current plot held
>> fun2=log10(f);
>> subplot(1,2,2);plot(f,fun2)

>> sqrt(4)
ans = 2
>> sqrt(683458)
ans = 826.7152
>> nthroot(16,4)
ans = 2
>> nthroot(2385214,547)
ans = 1.0272
>> nthroot(68957627517963537,43275465)
ans = 1.0000

S-ar putea să vă placă și