Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics."— Presentation transcript:

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

2 MATLAB and SimulinkLecture 52 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:

3 MATLAB and SimulinkLecture 53 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.

4 MATLAB and SimulinkLecture 54 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

5 MATLAB and SimulinkLecture 55 ODE Example: Solve the differential equation:

6 MATLAB and SimulinkLecture 56 ODE

7 MATLAB and SimulinkLecture 57 ODE Higher order differential equations must be rewritten into system of first order differential equations. m k b y F

8 MATLAB and SimulinkLecture 58 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

9 MATLAB and SimulinkLecture 59 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

10 MATLAB and SimulinkLecture 510 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

11 MATLAB and SimulinkLecture 511 Handle Graphics

12 MATLAB and SimulinkLecture 512 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

13 MATLAB and SimulinkLecture 513 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

14 MATLAB and SimulinkLecture 514 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.5000 Marker: '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]

15 MATLAB and SimulinkLecture 515 Handle Graphics To change the line width from default 0.5 to 5: set(Hndl,’LineWidth’,5)

16 MATLAB and SimulinkLecture 516 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.

17 MATLAB and SimulinkLecture 517 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

18 MATLAB and SimulinkLecture 518 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.

19 MATLAB and SimulinkLecture 519 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

20 MATLAB and SimulinkLecture 520 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 the board with the standard deviation 4 in x and y direction.

21 MATLAB and SimulinkLecture 521

22 MATLAB and SimulinkLecture 522 Exercises on this days topics


Download ppt "MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics."

Similar presentations


Ads by Google