You are on page 1of 13

AMITY SCHOOL OF ENGINEERING

AMITY UNIVERSITY UTTAR PRADESH

DEPARTMENT OF COMPUTER SCIENCE


& ENGINEERING

SIMULATION LAB [ES204]

PRACTICAL LAB FILE

SUBMITTED TO: SUBMITTED BY:


Ms. Nidhi Gaur Debabrata Pain
(A2305220415)
3CSE6Y
EXPERIMENT NO. 5

AIM:
a) Creating a vector X with elements, Xn = (-1)n+1/(2n-1) and Adding up 100 elements
of the vector, X;
b) 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
c) Plot the functions of the following: -
X = (3)^(3n)/(4n+1)
X = (-2)^(n^2)
A = x^10
B = A^15
C = B^0
F = x^2+(2*x)+1
F = (A+B)^2
F = (A-B)^2

SOFTWARE USED: MATLAB or Octave online (https://octave-online.net/)

THEORY:

The exp function is an elementary function that operates element-wise on arrays. Its domain
includes complex numbers.Y = exp(X) returns the exponential for each element of X. For
complex , it returns the complex exponential.
Exp

Exponential
Syntax
Y = exp(X)
Description
Y = exp(X) returns the exponential ex for each element in array X. For complex
elements z = x + iy, it returns the complex exponential
ez=ex(cosy+isiny) .
Use expm to compute a matrix exponential.
Examples
Numeric Representation of e
Try This Example
Calculate the exponential of 1, which is Euler's number, e.
exp(1)
ans = 2.7183
Euler's Identity
Try This Example
Euler's identity is the equality eiπ+1=0.

Compute the value of eiπ.


Y = exp(1i*pi)
Y = -1.0000 + 0.0000i
Plot Exponential Function
Try This Example
Plot y=ex/2 for x values in the range [−2,10].
X = -2:0.5:10;
Y = exp(X/2);
plot(X,Y)
Input Arguments
X — Input array
scalar | vector | matrix | multidimensional array
Input array, specified as a scalar, vector, matrix, or multidimensional array.

PROCEDURE:

To plot the graph of a function, you need to take the following steps:
1. Define x, by specifying the range of values for the variable x, for which the function is
to be plotted.
2. Define the function, y = f(x).
3. Call the plot command, as plot (x, y).
 CODE:

n=0:100;
Xn=[(-1).^(n+1)]./(2*n-1);
y=Xn;
sum(y);
disp(y);
plot(y);
x=0:1:4;
subplot(411);
plot(x);
title('plot of x');
xlabel('x');
ylabel('y');
y=x.^3;
subplot(412);
plot(y);
title('plot of x cube');
xlabel('x');
ylabel('y');
z=exp(x.^2);
subplot(413);
plot(z);
title('plot of x square');
xlabel('x');
ylabel('y');
41
v=exp(x);
subplot(414);
plot(v);
title('plot of e^x');
xlabel('x');
ylabel('y');
X = 0:4;
plot(X)
b = exp(X)
plot(b)
a = power(X,3);
plot(a)
c = exp(power(X,2));
plot(C)
w=[(3).^(3*x)./(4*x+1)]
plot(w)
title("Function 1")
xlabel("x")
ylabel("y")
m=[(-2).^(x.^2)]
plot(m)
title("Function 2")
xlabel("x")
ylabel("y")
a=x.^10
plot(a)
title("Function 3")
xlabel("x")
ylabel("y")
b=x.^15
plot(b)
title("Function 4")
xlabel("x")
ylabel("y")
c=x.^0
plot(c)
title("Function 5")
xlabel("x")
ylabel("y")
f=[x.^2+(2*x)+1]
plot(f)
title("Function 6")
xlabel("x")
ylabel("y")
g=(a+b).^2
plot(g)
title("Function 7")
xlabel("x")
ylabel("y")
h=(a-b).^2
plot(h)
title("Function 8")
xlabel("x")
ylabel("y")
INPUT:
OUTPUT:
RESULTS AND DISCUSSIONS:
In this experiment I was successfully able to understand and perform the exponential
functions such as Xn=(-1)n+1/(2n-1). I also performed and plotted the functions of x,
x^3, e^x and exp(x^2) in the Octave online and Matlab software.

PRECAUTIONS:
1) Don’t forget to login or sign-up on Octave online.
2) Save the code/input after completing it and before running it.
3) Saving the code and it’s output by downloading it on the computer after
completing the work.

Marking Criteria:

Criteria Total Marks Marks Obtained Comments

Concept (A)

Implementation (B)

Performance (C)

Total

You might also like