Using the Phase Plot Tool for MATLAB

Embed Size (px)

Citation preview

  • 7/30/2019 Using the Phase Plot Tool for MATLAB

    1/3

    Using thePhase Plot Toolfor MATLAB

    ThePhase Plot Toolis 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)

    orx1(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 initial condistions setting

    SETAX axes limits settingTIME cont. time (differential equations) or discrete time (difference equations)

    ANIM optimize the phase plot for printing or viewing (auxiliary)

    DECLARE differential equations definition

    PHASE 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 conditionssetic([-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]);

    % axes limitssetax(15,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 evolutionphase

    Additionalphase 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.

    a pair of initial conditions:x1 = -15, x = 8

    x1-limits: +/- 15, x2 limits: +/- 10

  • 7/30/2019 Using the Phase Plot Tool for MATLAB

    2/3

    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 conditionspairs [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 equationsx1' = fun1(x1,x2)x2' = fun2(x1,x2)

    The x1 and x2 symbols and standard notation are used for respectivesystem variables.NOTE: Be sure to use the 'array' operators such as .* ./ .\ etc.

    instead of simple * / \ (this arrangement is due to some technicalreasons 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 forcopying 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 abovefunction.The phase plot curves for additional initial conditions can beinteractively added by left or right mouse clicking in the existingfigure - just point the initial condition location in the graph usingthe mouse (use the right-click to reverse the time of the simulation)

  • 7/30/2019 Using the Phase Plot Tool for MATLAB

    3/3

    Using the cobweb function

    Syntax: COBWEB(FUN,X0,[ITER,CLR])

    Given the string FUN defining a function of one variable X and a vector ofstarting points X0 = [X01 X02 ...], the macro COBWEB(FUN,X0) plots the

    "cobweb" consisting of the points Xi, Xi = FUN(X(i-1)), along with thegraph of FUN(x), the axis of the first quadrant, and vertices andhorizontals related to the iterative process.

    Optional arguments ITER and CLR can be used to specify the number ofiterations for every starting point (its default value is 20) and colorrespectively (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 isadmissible. 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])