MatLab Handouts (4) --- MatLab Functions: int, subs, syms, ezplot
--- Picard's Method


  1. A Short-cut for Constructing Symbolic Objects.
    MatLab function syms sets a given letter to a symbolic object. For example,
        >> syms x t alpha beta
    
    Now x,t,alpha,beta can be used as variables in functions.

  2. Symbolic Substitution:
    MatLab function subs is designed for the symbolic substitution. Let g be a function in x. Then subs(g,x,t) replaces x in g by t. For example,
        >> syms x t 
        >> g=sin(x)+x^2+exp(-x)
           g = 
           sin(x)+x^2+exp(-x)
        >> subs(g,x,t)
           g = 
           sin(t)+t^2+exp(-t)
    
    Type help subs to learn more about this function.

  3. Symbolic Integration:
    MatLab function int is designed for the symbolic integration. Let g be a function in x. Then int(g,x,a,b) is the definite integral of g with respect to x from a to b. For example,
        >> syms x t a b
        >> g=sin(x)+x^2+exp(-x);
        >> int(g,x,0,b)
           (-cos(b)*exp(b)+1/3*b^3*exp(b)-1)*exp(-b)+2
        >> int(g,x,a,b)
           (-cos(b)*exp(b)+1/3*b^3*exp(b)-1)*exp(-b)
           +(cos(a)*exp(a)-1/3*a^3*exp(a)+1)*exp (-a)
    
    Type help int to learn how to find indefinite integrals and learn more about this function.

  4. Sketch the Graph of a Function over an interval [a,b]:
    ezplot(f,xmin,xmax) or ezplot(f,[xmin,xmax]) plots the graph of f(x) where f is a string or a symbolic expression representing a mathematical expression involving a single symbolic variable x. For example, the graph of f=-(xv+1)+4*exp(xv-1) for x in [1,5] can be generated by the following MatLab commands.
        >> syms x
        >> f=-(xv+1)+4*exp(xv-1); 
        >> ezplot(f,1,5)
    
    Type >>help ezplot to learn more about this function.

  5. Picard's Method:
    Now we can use above MatLab functions to compute approximations of the solution of a initial value problem
         y'=f(x,y),  y(x0)=y0
    
    by Picard's Method. Recall that the Picard Method generates a sequence of approximations: y1(x), y2(x), .... Review your class notes on Picard's Method if it is necessary.

    Consider the initial value problem: y'=x+y, y(1)=2. The solution of this problem is: y=-(x+1)+4ex-1. The following MatLab scripts compute the approximations y1, y2, y3 and y4 of y using Picard's Method and then plot the graphs of y1, y2, y3, y4 and y for x in [1,5].
        syms x t;
        y0=2;
        x0=1;
        f=t+y0;
        y1=int(f,t,x0,x)+y0;
        f=t+subs(y1,x,t);
        y2=int(f,t,x0,x)+y0;
        f=t+subs(y2,x,t);
        y3=int(f,t,x0,x)+y0;
        f=t+subs(y3,x,t);
        y4=int(f,t,x0,x)+y0;
        ysol=-(x+1)+4*exp(x-1);
        ezplot(y1,1,5)
        hold
        ezplot(y2,1,5)
        ezplot(y3,1,5)
        ezplot(y4,1,5)
        ezplot(ysol,1,5)
        hold off
        title('dy/dx=x+y, y(1)=2, Picard Method')
        text(1.5, 200,'solution y=-(x+1)+4e^{(x-1)}')
        text(1.5, 150,'y_1,y_2,y_3,y_4 -> solution')
        text(4.5,150,'y')
        text(4.5,110,'y_4')
        text(4.5,80,'y_3')
        text(4.5,50,'y_2')
        text(4.5,25,'y_1')
    
    Here is the graph: