Search code examples
maple

Taylor series vs numeric solution of nonlinear DE in maple


I want to plot two graphs: numeric solution of DE and Taylor series approximation for DE given. I have

de := diff(y(x), x$2) = x+y(x)-y(x)^2;
cond := y(0) = -1, (D(y))(0) = 1;
stp := 0.1e-1;
a, b := -5, 30;
numpts := floor((b-a)/stp+1);
p := dsolve({cond, de}, y(x), numeric, stepsize = stp, output = listprocedure); 

Plotting eval gives weird vertical line, while I expect to obtain plot that seems to oscillate as x -> ∞. For Taylor series, I've tried f:=[seq(taylor(y(x),x=i,n),i=-5..30 by stp)]; but seems like it won't work in such a way. What can I do with it? Why does my plot differ from expected?


Solution

  • restart;
    kernelopts(version);
    
        Maple 2018.0, X86 64 LINUX, Mar 9 2018, Build ID 1298750
    
    de := diff(y(x), x$2) = x+y(x)-y(x)^2:
    cond := y(0) = -1, (D(y))(0) = 1:
    stp := 0.1e-1:
    a, b := -5, 30:
    numpts := floor((b-a)/stp+1):
    
    p := dsolve({cond, de}, y(x), numeric, stepsize = stp,
                output = listprocedure):
    
    Y:=eval(y(x),p);
    
                    Y := proc(x)  ...  end;
    
    plot(Y, 0..20);
    

    enter image description here

    Order:=10:
    S := convert(rhs(dsolve({cond, de}, {y(x)}, series)),polynom);
    
    plot([S, Y(x)], x=0..1.5);
    

    enter image description here

    Order:=40:
    S := convert(rhs(dsolve({cond, de}, {y(x)}, series)),polynom):
    
    plot([S, Y(x)], x=0..2.0);
    

    enter image description here