You are on page 1of 3

Final Lab Evaluation

Basic Simulation Lab


(ES204)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Submitted to: Submitted by:


Dr. Pavika Sharma Prakhar Dubey
A2305219233

B.Tech CSE
3CSE-4X

AMITY SCHOOL OF ENGINEERING AND TECHNOLOGY


AMITY UNIVERSITY UTTAR PRADESH
NOIDA -201301
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. Also generating a random sequence using rand()/ randn() functions and plotting them.

Apparatus:
https://octave-online.net, GNU Octave

Theory:
If A is a vector, sum(A) returns the sum of the elements. If A is a matrix, sum(A) treats the columns of A as
vectors, returning a row vector of the sums of each column.

If A is a vector, then cumsum(A) returns a vector containing the cumulative sum of the elements of A.
If A is a matrix, then cumsum(A) returns a matrix containing the cumulative sums for each column of A.

Program:
clear all
clc
close all

%Sum
X = [ 1 8 3 9 0 1]
B = sum(X)

%running sum

totsum = 0
for i = 1:5
totsum += X(i);
i = i + 1;
totsum
end

E = cumsum(X)
F = cumsum (X,2)
G = cumsum ( X, 1)
R1= rand(4,5)
R2= randi(4,6)

%Plot
figure('name', "Figure of R1");
plot(R1);
title('graph of R1');
grid on;

figure('name', "Figure of R2");


plot(R2);
title('graph of R2');
grid on;
.
Result:

You might also like