matlab and simulinklecture 51 to days outline linear equations ode integration handle graphics....

22
MATLAB and Simul ink Lecture 5 1 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

Upload: kelly-cole

Post on 13-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 1

To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

Page 2: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 2

Linear Equations

Linear equations Using left division MATLAB uses Gaussian elemination

Has the solution in MATLAB X=A\Y

Example:

Solve the system of linear equation:

02

13

02

zyx

zyx

zyx

Page 3: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 3

ODE MATLAB can solve system of first order

ordinary differential equations with known initial condition.

MATLAB offers a number of different solvers ode45

This is the typical first solver to try on a new problem.

ode15s This is typical to try if ode45 fails or are too

inefficient. Solves stiff problems. Stiff problem are described as problem in which

the time constants vary a lot.

Page 4: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 4

ODE

General form [time,x]=solver(fh,t,x0)

time: Time values x: contains the solution for each time value solver: one of MATLAB’s ode solvers fh: A function handle to the function that

describes the differential equations t: is the time span T0 to TFINAL x0: Initial condition

Page 5: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 5

ODE

Example:Solve the differential equation:

1)0(

10 2

x

xdt

dx

Page 6: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 6

ODE

Page 7: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 7

ODE Higher order differential equations must be rewritten

into system of first order differential equations.

m

k

b

y

F

kyybFym

121

2

21

kxbxFm

x

xx

Page 8: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 8

Integration

Trapezoidal numerical integration. z = trapz(x,y)

computes the integral of y with respect to x using the trapezoidal method.

The trapezoidal technique is used when we only know the integrand in a number of specific points.

With a smaller delta-x the numerical integration becomes more accurate

Page 9: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 9

Handle Graphics A set of low level functions that

control the characteristic of a graphic object.

Changing grids, line color etc. that is not supported by the standard LinSpec option in the plot command.

MATLAB graphics system is based on a hierarchical system of Graphical Objects

Page 10: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 10

Handle Graphics Each graphical object are known

by a unique name: Handle Each graphical object has special

data: properties A handle is automatically returned

by any command that creates a graphic object. Hndl=figure

Page 11: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 11

Handle Graphics

Page 12: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 12

Handle Graphics When an object is created all of its

properties are initialized to default values. plot(y) uses the default line color, line style, line

width etc. All properties can be examined using:

get(Handle,’PropertyName’) ; All properties can be changed using:

set(Handle,’PropertyName’,Value1’,….); If value are left out MATLAB display a list of

possible property values for that actual property name

Page 13: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 13

Handle Graphics

To view all properties: x=[0:0.1:2]; y=x.^2; Hndl=plot(x,y) %Handle to the line. result=get(Hndl)

result will be a structure containing all properties to the line

Page 14: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 14

Handle Graphics

BeingDeleted: 'off'BusyAction: 'queue'ButtonDownFcn: ''Children: [0x1 double]Clipping: 'on'Color: [0 0 1]CreateFcn: ''DeleteFcn: ''EraseMode: 'normal'HandleVisibility: 'on'HitTest: 'on'Interruptible: 'on'LineStyle: '-'LineWidth: 0.5000Marker: 'none'

MarkerEdgeColor: 'auto' MarkerFaceColor: 'none' MarkerSize: 6 Parent: 101.0004 Selected: 'off' SelectionHighlight: 'on' Tag: '' Type: 'line' UIContextMenu: [] UserData: [] Visible: 'on' XData: [1x53 double] YData: [1x53 double] ZData: [1x0 double]

Page 15: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 15

Handle Graphics To change the line width from default

0.5 to 5: set(Hndl,’LineWidth’,5)

0 1 2 3 4 5 6 7-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

0 1 2 3 4 5 6 7-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 16: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 16

Handle Graphics Functions that return handles

gcf Get current figure.

gca Get current axes in the current figure.

gco Get current object in the current figure.

findobj Finds a graphics object with a specific property value

The current object is defined as the last object clicked on with the mouse.

Page 17: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 17

Handle Graphics

Position of figure Objects [left bottom width height]

Units can be: pixels, inches, cm, points and normalized coordinates.

Normalized coordinates are between 0-1. (0,0) = Lower left corner (1,1) = Upper right corner

Using normalized coordinates will make the figure to appear in the same relative position regardless of screen resolution.

Normalized coordinates are recommended to use if possible

Page 18: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 18

Handle Graphics

Position of axes and uicontrol Objects Also a 4-element vector.

[left bottom width height] Position is specified relative to the

figure that contains the object. Default units:

Normalized coordinates within the figure.

Page 19: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 19

Handle Graphics Position of text Objects The position of a text object refers to

the actual axes. x,y in 2D x,y,z in 3D

The position of the text object relative to a specified point is controlled by: HorizontalAlignment

{Left},Center,Right VerticalAlignment

{Middle}, Top, Cap, Baseline, Bottom

Page 20: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 20

Handle Graphics

Example:- Construct a dartboard with 10 circles.- Add text in each circle what the point would

be if the dart should hit within that circle.- Construct a frame around the dartboard.- Simulate that a person throw 10 darts at

theboard with the standard deviation 4 in x and y direction.

Page 21: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 21

The dart game

10987654321

Page 22: MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics

MATLAB and Simulink

Lecture 5 22

Exercises on this days topics