Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

LAB WORK:

Submitted by – KAUSHAL BHAGAT


Enrollment number – A35705220009
Course Code – ES204
Course name – Basic Simulation Lab
Batch – 2020-24
Submitted to – Mr.Pritam Keshari Sahoo
EXPERIMENT- 3
AIM: Generating a set of Commands on a given Vector
(Example: X = [1 8 3 9 0 1]) to (A). Add up the values of the
elements (Check with sum) (B). Compute the Running Sum
(Check with sum), where Running Sum for element j = the
sum of the elements from 1 to j, inclusive. (C) Generating a
Random Sequence using rand() / randn() functions and plot
them.

1. ADD VALUES IN A VECTOR:

>> sum = 0;
for i = 1:5
sum = sum+i;
end
display(sum)

OUTPUT
sum =
15

2. CHECK SUM:

>> A = [1 2 3 4 5]
OUTPUT
A=
1 2 3 4 5

>> B = sum(A)
OUTPUT
B=
15

3. CHECK RUNNING SUM:


>> sum = 0;
>> for i = 1:5
sum = sum+i;
display(sum)
end

OUTPUT
sum =
1
sum =
3
sum =
6
sum =
10
sum =
15

4. CHECK CUMSUM:

>> A = [1 2 3 4 5]
OUTPUT
A=
1 2 3 4 5
>> B = cumsum(A)
OUTPUT
B=
1 3 6 10 15

5. RANDOM:

>> B = rand(3)
OUTPUT
B=
0.4447 0.9218 0.4057
0.6154 0.7382 0.9355
0.7919 0.1763 0.9169

>> plot(B)

You might also like