NAME
: AAVISHKAR
ROLL NO. : 211216
ACTIVITY-1
INTRODUCTION TO MATLAB
Start screen of MATLAB:
We have used the following commands in MAT-
LAB program:
Mathematical op erations in MATLAB:
We have use the following operations in our program in Matlab
Addition (+), Subtraction ( –), Multiplication (*), Division (/), Power (^)
Log(x), sin(), cos(), tan(), sqrt(x) , pi, log 10 (x), exp(x) .
ACTIVITY- 2 (23-07-2022)
Basic matrix operations:-
Creating a matrix:a=[3 ,7 ,3] and [6 2 7;9 7 2]
Addition and subtraction of matrix:
c+c
Operations on matrix:
A) size ():
b) trace ():
c) rank ():
d) inv ():
e) c.*c :
Getting the elements from a given matrix:
Matrix:
To find:
p(3,5)
p(1,2)
p(3,1:5)
p([3,5],[3,5])
ACTIVITY-3(27-07-2022)
PLOT THE GRAPH
To plot the graph of a function, you need to take the follow-
ing steps −
• Define x, by specifying the range of values for the variable
x, for which the function is to be plotted
• Define the function, y = f(x)
• Call the plot command, as plot(x, y)
First we define the variables and assign the range for them:
• X1=[0:1:100]
• X2=[0:0.1:100]
• X3=linspace(0,2*pi,100)
• Y1=sin(x1)
• Y2=sin(x2)
• Y3=sin(x3)
• Y4=cos(x3)
• Y5=exp(x3)
For plotting the graphs we use the plot () and stem() key-
word:
• Plot(x3,y3)
• Plot(y3,y4)
• Plot(x3,y5)
• stem (x3,y3)
• plot(x3,y3,x3,y4)
• plot(x3,y3,’--’,x3,y4,’-*’)
• plot(x3,y3,’--r’,x3,y4,’-*b’)
• xlabel(‘X-value’)
• ylabel(‘y-value’)
• title(‘my-plot’)
• legend(‘sin(x)’,’cos(x)’)
Graphs:
• plot(x3,y3):
• plot(x3,y5):
• plot(y3,y4):
• using hold on command to plot 2 or more graphs together:
• stem(x3,y3):
• plot(x3,y3,x3,y4)
• plot(x3,y3,’--’,x3,y4,’-*b’)
• plot(x3.y3,’--r’,x3,y4,’-*b’)
• using the grid command to get grids on your graph
NAME : AAVISHKAR
ROLL NO. : 211216
ACTIVITY-1
EXAMPLE = LET US PLOT THE GRAPH WHERE x = [0:5:100]; y = x; plot(x, y)
PLOT THE GRAPH OF A FUNCTION, YOU NEED TO TAKE THE
FOLLOWING STEPS −
· DEFINE X, BY SPECIFYING THE RANGE OF VALUES FOR THE VARIABLE X,
FOR WHICH THE FUNCTION IS TO BE PLOTTED
· DEFINE THE FUNCTION, Y = F(X)
· CALL THE PLOT COMMAND, AS PLOT(X, Y)
ADDING TITLE, LABELS, GRID LINES AND SCALING ON
THE GRAPH:
MATLAB ALLOWS YOU TO ADD TITLE, LABELS ALONG THE X-AXIS AND Y-AXIS,
GRID LINES AND ALSO TO ADJUST THE AXES TO SPRUCE UP THE GRAPH.
· THE X-LABEL AND Y-LABEL COMMANDS GENERATE LABELS ALONG X-
AXIS AND Y-AXIS.
· THE TITLE COMMAND ALLOWS YOU TO PUT A TITLE ON THE GRAPH.
· THE GRID ON COMMAND ALLOWS YOU TO PUT THE GRID LINES ON THE GRAPH.
EXAMPLE 2 = TO PLOT THE GRAPH OF x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'),
grid on, axis equal
· THE AXIS EQUAL COMMAND ALLOWS GENERATING THE PLOT WITH
THE SAME SCALE FACTORS AND THE SPACES ON BOTH AXES.
· THE AXIS SQUARE COMMAND GENERATES A SQUARE PLOT.
EXAMPLE = 3 : TO PLOT THE GRAPH OF MULTIPLE FUNCTION
ON SAME GRAPH
X = [-10 : 0.01: 10];
Y = 3*X.^4 + 2 * X.^3 + 7 * X.^2 + 2 * X + 9;
G = 5 * X.^3 + 9 * X + 2;
PLOT(X, Y, 'R', X, G, 'G')
x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)')
SETTING COLOR IN
GRAPH: EXAMPLE
LET US DRAW THE GRAPH OF TWO POLYNOMIALS
4 3 2
· F(X) = 3X + 2X + 7X + 2X + 9 AND
3
· G(X) = 5X + 9X + 2
CREATE A SCRIPT FILE AND TYPE THE FOLLOWING CODE −