You are on page 1of 3

Using the Phase Plot Tool for MATLAB

The Phase Plot Tool is a set of MATLAB programs for plotting the planar phase plots of sets of two differential or difference equations given in the form x1' = f1(x1,x2) x2' = f2(x1,x2) (differential equations) or x1(k+1) = f1(x1,x2) x2(k+1) = f2(x1,x2) (difference equations) Installation instructions Unzip the PHASE.ZIP file and add the obtained ../phase directory to the MATLAB path. Description The tool consists of the following components SETIC SETAX TIME ANIM DECLARE PHASE initial condistions setting axes limits setting cont. time (differential equations) or discrete time (difference equations) optimize the phase plot for printing or viewing (auxiliary) differential equations definition plot the phase plot

Their usage is illustrated by an example below. Five demos titled DEMOPH1.M to DEMOPH5.M are directly available in the /PHASE directory and can be invoked within the MATLAB prompt. Example: % demoph1.m: phase plot of undamped pendulum % initial conditions setic([-15 8;-15 7; -15 6;-15 5;-15 4; -15 3; -15 2; -15 1;... -3.2 0; -4 0; -5 0; -5.8 0; -6.4 0;-3 0;-2 0;-1 0; -0.5 0;... 3.2 0; 4 0; 5 0; 5.8 0; 6.4 0;... 15 -1; 15 -2; 15 -3; 15 -4;15 -5;15 -6; 15 -7;15 -8]); a pair of initial conditions: x1 = -15, x = 8 % axes limits setax(15,10) x1-limits: +/- 15, x2 limits: +/- 10

% functions: declare(f1,f2), where % x1' = f1(x1,x2) = x2 % x2' = f2(x1,x2) = -sin(x1) declare('x2', '-sin(x1)') % phase plot with time evolution phase Additional phase plot curves for more initial conditions can be added by left or right mouse clicking in the existing figure (use the right-click to reverse the time of particular simulation). Optionally, the SETIC command neednot be called at all - all initial conditions are defined by mouse clicking in such a case.

Description:
SETIC Modify the initial conditions matrix for the PHASE PLOT tool. Syntax: SETIC(INITS), where INITS is a n-by-2 matrix [X11 X21; ..., X1n X2n] representing the set of initial conditions pairs [X1i X2i] SETIC 0 or SETINIT(0) Zeros all entries of IC.

SETAX Set axes limits for PHASE PLOT tool. SETAX(LIM) sets the x and y axes limits symmetricaly to [-LIM,+LIM] SETAX(XLIM,YLIM) sets the x and y axes limits symmetricaly to [-XLIM, XLIM] and [-YLIM,YLIM] respectively. SETAX(XLIMminus,XLIMplus,YLIMminus,YLIMplus) serves for nonsymmetric setting

DECLARE Define the differential equations of the system. Syntax: DECLARE(FUN1,FUN2), where FUN1 and FUN2 are strings defining the right hand side of involved differential equations x1' = fun1(x1,x2) x2' = fun2(x1,x2) The x1 and x2 symbols and standard notation are used for respective system variables. NOTE: Be sure to use the 'array' operators such as .* ./ .\ etc. instead of simple * / \ (this arrangement is due to some technical reasons only). Example: declare('x2', '-sin(x1)') declare('x1+x2.^2', '-(x1.^3+1)./(x1.*x2)')

ANIM Optimize the phase portrait picture for viewing or printing. ANIM NO causes the PHASE command to produce an image suitable for copying or printing (DEFAULT). ANIM YES causes the PHASE command to produce additional "comet's tail" convenient for viewing the motion of the concerned system.

TIME Define the time domain (auxiliary function). TIME C switches the time to the continuous version - a set of related DIFFERENTIAL equation is considered by the PHASE command (DEFAULT). TIME D switches the time to the discrete version - a set of related DIFFERENCE equation is considered by the PHASE command.

PHASE Create the phase portrait for the system defined by the above function. The phase plot curves for additional initial conditions can be interactively added by left or right mouse clicking in the existing figure - just point the initial condition location in the graph using the mouse (use the right-click to reverse the time of the simulation)

Using the cobweb function


Syntax: COBWEB(FUN,X0,[ITER,CLR]) Given the string FUN defining a function of one variable X and a vector of starting points X0 = [X01 X02 ...], the macro COBWEB(FUN,X0) plots the "cobweb" consisting of the points Xi, Xi = FUN(X(i-1)), along with the graph of FUN(x), the axis of the first quadrant, and vertices and horizontals related to the iterative process. Optional arguments ITER and CLR can be used to specify the number of iterations for every starting point (its default value is 20) and color respectively (valid for scalar XO only) NOTE: Use the array operators .* ./ .\ instead of simple * / \.

Example: cobweb('3.*x.*(1-x)', [0:0.1:0.5])

Animated version is also available in the form of COBWEB2.M function. In this case, only scalar X0 is admissible. Be sure the MATLAB command window and the graph window are not overlapped. To proceed animation, press enter. To finish, press 0 and enter. Example: cobweb2('3.*x.*(1-x)', [0.2])

You might also like