18
S i m u l i n k Prof. Muhammad Saeed hematical Modeling and Simulati Using MATLAB MATLAB 1

S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

Embed Size (px)

Citation preview

Page 1: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

S i m u l i n kS i m u l i n k

Prof. Muhammad Saeed

Mathematical Modeling and Simulation

UsingMATLABMATLAB

1

Page 2: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

2

Introduction How to start?

Block Library Model Blocks Virtual Non-virtual User-defined Ports Time States Continuous Discrete Hybrid Parameters Normal Tunable Sample Time Subsystems

Page 3: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

3

Page 4: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

4

Creating Models Block Selection

Sources Sinks System Blocks

Block Editing Color Size Alignment Labeling Parameters and states

Connecting BlocksGroup Blocks

Page 5: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

5

y

To WorkspaceSine Wave3

Sine Wave2

Sine Wave1

Sine Wave

Scope2

Scope1

Scope

Product

4

Gain2

5

Gain1

4

Gain

30

Display1

200

Display

20

Constant3

10

Constant2

20

Constant1

10

Constant

Add

Model Blocks:

Source Sink Multiplication and Division Addition and Subtraction

Page 6: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

6

y3

To Workspace3

y2

To Workspace2

y1

To Workspace1

Sum ofElements

Product3

MatrixMultiply

Product2

Product1

Dot Product

18

Display2

30

Display1

1 1 21 2 21 3 5

Constant7

1 2 34 5 61 1 2

Constant6

[2 2 2 2 2]

Constant5

[1 2 3 4 5]

Constant4

[2 2 2 2 2]

Constant3

[1 2 3 4 5]

Constant2

1 1 21 2 21 3 5

Constant1

Model Blocks:

Sum Dot Product Vector Multiplication Matrix Multiplication

Element by Element By Matrix Rule

Page 7: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

7

sin

TrigonometricFunction

y4

To Workspace4

y3

To Workspace3

y2

To Workspace2

y1

To Workspace1

y

To Workspace

floor

Rounding Function

Product of Elements

P(u)O(P) = 7

Polynomial

max

MinMax

eu

Math Function

5

Display1

10

Display

[3x3]

Constant6

-C-

Constant5

[1 2 3 4 5]

Constant4

2 -1 3 3 4 6-3 -1 8

Constant3

2 -1 3 3 4 6-3 -1 8

Constant2

2 -1 3 3 4 6-3 -1 8

Constant1

-10

Constant

|u|

Abs

Model Blocks:Built-in Functions

abs max, min Logarithmic, exponential Trigonometric Polynomial Product Rounding off

Page 8: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

8

Model Blocks:User-defined Functions

Embedded Matlab FunctionFunction of Matlab FunctionsMatlab Function

XY Graph

Scope1

Scope

sin(u)*cos(u)

Fcn

MATLABFunction

Exp

u ydampOsc

EmbeddedMATLAB Function

Clock2

Clock1

Clock

Page 9: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

9

Differential Equation Models

1.

Sine WaveScope

1s

Integrator

10

Gain

y

To Workspace

Sine Wave

1s

Integrator

10

Gain

Clock

Page 10: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

10

Differential Equation Models

2.

Sine WaveScope

1s

Integrator

10

Gain

Page 11: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

11

Differential Equation Models

Page 12: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

12

Differential Equation Models

Page 13: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

13

Differential Equation Models

Step

x' = Ax+Bu y = Cx+Du

State-Space Scope

Page 14: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

14

3.

Differential Equation Models

Page 15: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

15

Differential Equation Models

Step

x' = Ax+Bu y = Cx+Du

State-Space Scope

Page 16: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

16

If else For While switch

Page 17: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

17

5

c

10

b

-1

a

else { }In1 Out1

If ActionSubsystem3

elseif { }In1 Out1

If ActionSubsystem2

elseif { }In1

In2Out1

If ActionSubsystem1

if { }In1

In2Out1

If ActionSubsystem

u1

u2

u3

if(u1 ~=0 & u2<10)

elseif(u2<0)

elseif(u3<u2)

else

If

8

Display3

0

Display2

0

Display1

0

Display

8

Constant3

1

Constant2

3

Constant1

10

Constant

IF Block

Page 18: S i m u l i n k Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB 1

18

END