Slide MATLAB
Slide MATLAB
Conducted By
Md. Tarequzzaman
Lecturer
Dept. of EEE, JUST
Introduction to MATLAB
This window shows all the files in the directory and the folder
directory.
The Workspace pane of the default desktop window shows the current
entries and saved variables during the session.
Command Window and Variables
Access: Thus, v(1) is the first element of vector v, v(2) its second element,
and so forth.
Furthermore, to Or, all elements Entering a matrix
access blocks of from the third
elements, we through the last A matrix is an array of
use MATLAB’s elements, numbers. To type a matrix
colon notation into MATLAB you must-
(:). • begin with a square
where end signifies
the last element in bracket, [
the vector. • separate elements in a
row with spaces or
commas (,)
• use a semicolon (;) to
Location: (3,2) separate rows
• end the matrix with
another square bracket, ]
Matrix indexing
Correcting any entry is easy
The element of row i and column j of the through indexing. Here we
matrix A is denoted by A(i,j). Thus, A(i,j) substitute A(3,3)=9 by A(3,3)=0.
in MATLAB refers to the element Aij of The result is
matrix A. The first index is the row
number and the second index is the
column number. For example, A(1,3) is
an element of first row and third column.
Linear spacing
Colon operator
On the other hand, there is a command
Often we must deal with to generate linearly spaced vectors:
matrices or vectors that are too linspace. It is similar to the colon
large to enter one element at a operator (:), but gives direct control
time. For example, suppose we over the number of points. For
want to enter a vector x example,
consisting of points (0; 0:1; 0:2;
0:3; 5). We can use the
command generates a row vector y of 100 points
linearly spaced between and including
a and b.
ySol(t) = dsolve(ode)
ySol(t) = C1*exp(t^2/2)
Solve Differential Equation with Condition
cond = y(0) == 2;
ySol(t) = dsolve(ode,cond)
syms u(x)
Du = diff(u,x);
D2u = diff(u,x,2); fun = @(x) exp(-
x.^2).*log(x).^2;
ode = diff(u,x,3) == u; Evaluate the integral from x=0 to
cond1 = u(0) == 1; x=Inf.
cond2 = Du(0) == -1; q = integral(fun,0,Inf)
cond3 = D2u(0) == pi;
conds = [cond1 cond2
cond3];
uSol(x) = dsolve(ode,conds)
uSol(x) = fun = @(x)log(x);
(pi*exp(x))/3 - exp(-x/2)*cos((3^(1/2)*x)/2)*(pi/3 -
1) - (3^(1/2)*exp(-x/2)*sin((3^(1/2)*x)/2)*(pi + 1))/3 format long
q1 =
integral(fun,0,1)
Introduction to Plotting
MATLAB’s extensive, device-
independent plotting
capabilities are one of its most
powerful features.
To plot a data set, just create
two vectors containing the x and
y values to be plotted and use
the plot function.
legend('string1', 'string2',...,
pos)
x = linspace(-2*pi,2*pi); subplot(m,n,p) divides
y1 = sin(x); the current figure into
y2 = cos(x); an m-by-n grid and
figure creates axes in the
plot(x,y1,'r-',x,y2,'bo',... position specified by p.
'LineWidth',2,...
'MarkerSize',2,... subplot(2,1,1);
'MarkerEdgeColor','b',...
x = linspace(0,10);
'MarkerFaceColor',[.3,.3,.3])
title('X Vs Y') y1 = sin(x);
xlabel('X') plot(x,y1)
ylabel('Y')
%legend('V','I') subplot(2,1,2);
legend({'V','I'},'Location','southwest','NumColumns y2 = sin(5*x);
',1) plot(x,y2)
%legend('off')
Semi log
Graph
x = logspace(-1,2);
y1 = x;
y2 = -x; Loglog Graph
semilogx(x,y1,x,y2)
grid on x = logspace(-1,2);
y1 = 10.^x;
y2 = 1./10.^x;
loglog(x,y1,x,y2)
grid on