Basic Simulation Lab File
Basic Simulation Lab File
TECHNOLOGY
AMITY UNIVERSITY
----------- UTTAR PRADESH-----------
Shubhangi Singhal
A2305216321
4CSE5-X
INDEX
EXPERIMENT NO 1
Theory:
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).
Suggested Program:
b = [10;20;30;40;50;60;70]
c = [1 2 3; 4 5 6; 7 8 9];
d = c;
a = b;
c + d;
c - d;
c * d;
inv(c);
rank(c);
rank(a);
rank(b);
rank(d);
2^5;
1000000000 ^1000000;
a = [1 2 3 4 5];
b = a;
b.^2;
b.^3;
Output:
Ans (c+d) = 2 4 6
8 10 12
14 16 18
Ans (c-d) = 000
000
000
ans (c*d) = 30 36 42
66 81 96
102 126 150
Ans (inv(c)) = 1.0e+016 *
-0.4504 0.9007 -0.4504
0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504
Ans (rand(c)) = 2
Ans (rank(a)) = 1
Ans (rank(b)) = 1
Ans (rank(d)) = 2
Ans (2^5) = 32
Ans (100… ^ 100…)= Inf
Ans (b.^2) = 1 4 9 16 25
Ans (b.^3) = 1 4 27 256 3125
EXPERIMENT NO 2
THEORY:
● Arithmetic Operators
● Relational Operators
● Logical Operators
● Bitwise Operations
● Set Operations
● Arithmetic Operators
PROCEDURE:
Operator Description
Addition or unary plus. A+B adds A and B. A and B must have
+ the same size, unless one is a scalar. A scalar can be added to a
matrix of any size.
Subtraction or unary minus. A-B subtracts B from A. A and B
- must have the same size, unless one is a scalar. A scalar can be
subtracted from a matrix of any size.
Matrix multiplication. C = A*B is the linear algebraic product of
the matrices A and B. More precisely,
*
For nonscalar A and B, the number of columns of A must equal
the number of rows of B. A scalar can multiply a matrix of any
size.
SUM = 0;
for i = 1:mn(2)
ROWSUM = 0;
for j = 1:mn(1)
ROWSUM = x(i,j) + ROWSUM;
SUM = x(i,j) + SUM;
end
ROWSUM
end
SUM
OUTPUT
x=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
ans =
34 34 34 34
ans =
34 34 34 34
ans =
34
34
34
34
y=
1 2 3 4 5 6 7 8 9 10
ans =
1 3 6 10 15 21 28 36 45 55
ans =
16 2 3 13
21 13 13 21
30 20 19 33
34 34 34 34
ans =
16 18 21 34
5 16 26 34
9 16 22 34
4 18 33 34
ROWSUM =
34
ROWSUM =
34
ROWSUM =
34
ROWSUM =
34
SUM =
136