0% found this document useful (0 votes)
57 views18 pages

Introduction To Matlab: Hasitha Nayanajith

This document provides an introduction and overview of MATLAB. It discusses what MATLAB is, which is a numerical computing environment and programming language. It then describes some of MATLAB's basic desktop tools like the command window and workspace. It also outlines some common operators in MATLAB like those for arithmetic, relational logic, and vectors. Finally, it gives examples of how to use MATLAB for tasks like plotting graphs, working with matrices and arrays, basic statistics, and solving ordinary differential equations.

Uploaded by

Amila Kumara
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views18 pages

Introduction To Matlab: Hasitha Nayanajith

This document provides an introduction and overview of MATLAB. It discusses what MATLAB is, which is a numerical computing environment and programming language. It then describes some of MATLAB's basic desktop tools like the command window and workspace. It also outlines some common operators in MATLAB like those for arithmetic, relational logic, and vectors. Finally, it gives examples of how to use MATLAB for tasks like plotting graphs, working with matrices and arrays, basic statistics, and solving ordinary differential equations.

Uploaded by

Amila Kumara
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Introduction to Matlab

HASITHA NAYANAJITH
Department of Mechanical Engineering
ATI- Labuduwa
What is Matlab

MATLAB (for matrix laboratory) is a numerical
computing environment and fourth-generation
programming language. Developed by MathWorks,
MATLAB allows matrix manipulations, plotting
of functions and data, implementation of algorithms,
creation of user interfaces, and interfacing with
programs written in other languages,
including C, C++, and Fortran.
Desktop Tools (Matlab v6)

• Command Window
– type commands

• Workspace
– view program variables
– clear to clear
– double click on a variable
to see it in the Array Editor

• Command History
– view past commands
– save a whole session using
diary
Operators (arithmetic)

+ addition
- subtraction
* multiplication .* element-by-element mult
/ division ./ element-by-element div
^ power .^ element-by-element power
‘ complex conjugate .‘ transpose
transpose
Operators (relational, logical)

== equal pi 3.14159265…
~= not equal j imaginary unit, 1
< less than i same as j
<= less than or equal
> greater than
>= greater than or equal

& AND
| OR
~ NOT
EXAPLE -01

• a=10
• b=5
+ addition
- subtraction
* multiplication
/ division
^ power

• a*5+(3*b)*2((b-6)^(10/b))
Useful Notations

• >> pi
• >> format long
• >> format short
• e=exp(1)
• sin(a), cos(a), tan(a)
• asin(a), acos(a), atan(a)
• sinh(a), cosh(a), tanh(a)
• asinh(a), acosh(a), atanh(a)
• log2(e)
• log(e)
• log10(e)
• c =0.5+0.866025i
• abs(c)
• angle(c)
• real(c)
• imag(c)
Vectors

• v = [ 1 3, sqrt(5)]
• v3 = [3 +4 5]
• v + v3
• v4 = [v , v3]
• sort(v4)
• v4(2)
• v4(2)=5
Array

• 1:4
• 1:2:10
Plot a Graph

• x = linspace (0,1,11); • title('Graph of y = sin(3pi x)')


• y = sin(3*pi*x); • xlabel('x axis')
• plot(y, x) • ylabel('y-axis')
• grid
• plot(x,y)
• x = 0:0.00001:1;
• plot(x,y)
Colours & Line Styles

y yellow . point
m magenta o circle
c cyan x x-mark
r red + plus
g green - solid
b blue * star
w white : dotted
k black -. dashdot
-- dashed
Matlab Graphics

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')
Multiple Graphs

t = 0:pi/100:2*pi;
y1=sin(t);
y2=sin(t+pi/2);
plot(t,y1,t,y2)
grid on

plot(t,y1,'go',t,y2,'rx')
Graph Functions (summary)

• plot linear plot


• stem discrete plot
• grid add grid lines
• xlabel add X-axis label
• ylabel add Y-axis label
• title add graph title
• subplotdivide figure window
• figure create new figure window
• pause wait for user response
Statistics

• A=[1 2 3 6 2 12 8 1 25 2]
• max(A)
• min(A)
• sort(A)
• mean(A)
• median(A)
• std (A)
single 1st-order ode
x'(t)=sin(tx(t)) with x(0)=1 for 0 < t < 20.

function xpr=firstode(t,x); 
%This M-file is used with ode45 to
solve the differential equation 
% x'(t)=sin(tx(t)) 

xpr=sin(t*x);
» [t,x]=ode45('firstode',[0,20],1); 
» plot(t,x) 
» grid on
» title('Solution to x''=sin(tx), x(0)=1')
• Thakyou

You might also like