Sie sind auf Seite 1von 31

INTRODUCTION TO

MATLAB

MATrix LABoratory
1970s
DR. CLEVE MOLER
University of New Mexico

COMMERCIALIZATION
1980s
MathWorks

MATLAB
High performance numerical computation

Visualization

Interactive environment

Academics & Industry

MATLAB
Graphics
Computations
External Interface

MATLAB Toolboxes
Signal Processing
Statistics
Control Systems
Neural Networks
Communications
Image Processing
Optimization

MATLAB Powerful
Software
Symbolic Algebra
(x + y)^2 = x^2 + 2xy +y^2

MATLAB is a Computer Algebra System

MATLAB Windows
Main Window

Command Window

For writing
commands
Shows the simulation
results

Workspace

Stores Variables

Command History

Shows history of
commands used

Editor Window

M-File

Coding/Program

Model Window(Simulink)

Model file

Circuit

MATLAB

M-File Programming
Simulink

M-file programming
Basic Operations
1. X = 2^3/(4)
X= 2
2. X = 2^3/(4) ;
3. exp(3)
ans = 20.0855
4. log(2)
ans = 0.6931

Basic Operations
5. sin(pi/6)
ans = 0.5
6. sind(30)
ans = 0.5
7. x = (1+3i) / (1-3i)
x = -0.8 + 0.6i

Vectors and Matrices


1. A = [1 2 3]
A=123
2. B = [1 2 3
4 5 6]
B=123
456
3. C = [1 2 3;4 5 6]
C=123
456

Vectors and Matrices


4. A = 2 * B;
5.

x = [1 2 3 4 5];
y = [1 2 3 4 5];
z = x.*y
z = 1 4 9 16 25

6. x = [1 2 3 4 5];
x
ans = 1
2
3
4
5

Vectors and Matrices


7. x = [1 2 3 4 5];
y = [1 2 3 4 5];
z = x*y
z = 55
8. a = [0 30 45 60 90];
b = sind(a)
b = 0 0.5000 0.7071 0.8660 1.0000

Vectors and Matrices


9. x = 1:5
x=12345
10. x = 1:0.5:5
x = 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
11.

x = linspace(1,10,10)
x = 1 2 3 4 5 6 7 8 9 10

12. x = linspace(2,10,5)
x = 2 4 6 8 10

Vectors and Matrices


13. A = zeros(2)
A= 0 0
0 0
14. B = eye(2)
B= 1 0
0 1
15. C = ones(2)
C= 1 1
1 1

Graphs and Plots


M-File for drawing Circle with radius = 2 untis

theta = linspace(0,360,100);
X = 2*cosd(theta);
Y = 2*sind(theta);
plot(X,Y);
xlabel(x-axis);
ylabel(y-axis);
title(Circle);

Graph of Circle with radius = 2 units

Plot as a function of Stem

theta = linspace(0,360,50);
x = sind(theta);
stem(x);

x = linspace(1,10,5);
bar(x)

Plot as a function of Bar

Simulink
Simulink Library Browser

Toolboxes

Building Blocks

Using the Simulink


Using Simple blocks Blocks

Output of Constant block = 2

Output of Gain block = 10

Using Sum Block

Function generation

Frequency = 50 Hz
Frequency(rad/sec)=2*pi*f

Absolute Value Block

Sine Wave

Rectified Sine Wave


(Only Positive Value)

Derivative of a Function

Sine Wave

Cosine Wave
(Derivative of Sine Wave)

Detecting Positive and Negative Region

Sine Wave

Output = 1 for
Positive region

Output = -1 for
Negative region

Simple Electrical Circuit

Current measurement block

Voltage
measurement
block

AC Supply

Resistive Load

Simple Electrical Circuit


..(Contd.)

Supply Voltage
Waveform

Load Current
Waveform

Thank You

Das könnte Ihnen auch gefallen