220 likes | 387 Views
To days Outline. Linear Equations ODE Integration Handle Graphics. Exercises on this days topics. Linear Equations. Linear equations Using left division MATLAB uses Gaussian elemination Has the solution in MATLAB X=AY Example: Solve the system of linear equation:. ODE.
E N D
To days Outline • Linear Equations • ODE • Integration • Handle Graphics. • Exercises on this days topics Lecture 5
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: Lecture 5
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. Lecture 5
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 Lecture 5
ODE Example: Solve the differential equation: Lecture 5
ODE Lecture 5
ODE • Higher order differential equations must be rewritten into system of first order differential equations. y b m F k Lecture 5
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 Lecture 5
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 Lecture 5
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 Lecture 5
Handle Graphics Lecture 5
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 Lecture 5
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 Lecture 5
Handle Graphics Lecture 5
Handle Graphics • To change the line width from default 0.5 to 5: • set(Hndl,’LineWidth’,5) Lecture 5
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. Lecture 5
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 Lecture 5
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. Lecture 5
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 Lecture 5
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. Lecture 5
Exercises on this days topics Lecture 5