Professional Documents
Culture Documents
Engineering(CHE3001)
Lab Component
Dr. Bandaru Kiran
Assistant Professor Sr.
SCHEME
VIT Vellore
Mob: 7981343089
Getting Started With Matlab
• Sum
• transpose
• diag
• Transpose
• Inverse
• Product
Operators
Determinant : det(A)
Inverse: inv(A)
Eigen values: eig(A)
Arrays
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
xlabel('x = 0:2\pi')
ylabel('Sine of x')
title('Plot of the Sine Function','FontSize',12)
Plot
Multiple Data set in Single Graph
x = 0:pi/100:2*pi;
y1=sin(x);
y2 = sin(x-.25);
y3 = sin(x-.5);
plot(x,y1,x,y2,x,y3)
legend('sin(x)','sin(x-.25)','sin(x-.5)') % Legend
Multiple Plots in one Figure
The elseif and else blocks are optional. The statements execute only if
previous expressions in the if...end block are false. An if block can include
multiple elseif blocks.
Syntax: if
If()
expression statements
elseif
expression statements
else
statements
end
Exaxmple Code
• Create a matrix of 1s
• nrows = 4; ncols = 6;
• A = ones(nrows,ncols);
• Loop through the matrix and assign each element a
new value. Assign 2 on the main diagonal, -1 on the
adjacent diagonals, and 0 everywhere else.
for c = 1:ncols
for r = 1:nrows
if r == c
A(r,c) = 2;
elseif abs(r-c) == 1
A(r,c) = -1;
else
A(r,c) = 0;
end
end
end
While Loop