Sharedcloud-examples / sage / Picard.ipynbOpen in CoCalc
Jupyter notebook cloud-examples/sage/Picard.ipynb
def picard_iteration(f, a, c, N):
    '''
    Computes the N-th Picard iterate for the IVP  

        x' = f(t,x), x(a) = c.

    EXAMPLES:
        sage: var('x t s')
        (x, t, s)
        sage: a = 0; c = 2
        sage: f = lambda t,x: 1-x
        sage: picard_iteration(f, a, c, 0)
        2
         sage: picard_iteration(f, a, c, 1)
        2 - t
        sage: picard_iteration(f, a, c, 2)
        t^2/2 - t + 2
        sage: picard_iteration(f, a, c, 3)
        -t^3/6 + t^2/2 - t + 2
        sage: var('x t s')
        (x, t, s)
        sage: a = 0; c = 2
        sage: f = lambda t,x: (x+t)^2
        sage: picard_iteration(f, a, c, 0)
        2
        sage: picard_iteration(f, a, c, 1)
        t^3/3 + 2*t^2 + 4*t + 2
        sage: picard_iteration(f, a, c, 2)
        t^7/63 + 2*t^6/9 + 22*t^5/15 + 16*t^4/3 + 11*t^3 + 10*t^2 + 4*t + 2

    '''
    if N == 0:
        return c*t**0
    if N == 1:
        #print integral(f(s,c*s**0), s, a, t)
        x0 = lambda t: c + integral(f(s,c*s**0), s, a, t)
        return expand(x0(t))
    for i in range(N):
        x_old = lambda s: picard_iteration(f, a, c, N-1).subs(t=s)
        #print x_old(s)
        x0 = lambda t: c + integral(f(s,x_old(s)), s, a, t)
    return expand(x0(t))
v=var('x t s')
a = 0; c = 4; N=40; b=8; x1=-5; x2=10;
f = lambda t,x: sin(t)-2*x; assume(t>0) 
z=[picard_iteration(f, a, c, i) for i in range(N+1)]
for i in range(N+1):
    show(z[i])
from sage.plot.colors import rainbow
c=rainbow(N+1)
where = [x,-2+1.5,b]
p=plot(-1/5*(cos(t)*e^(2*t) - 2*e^(2*t)*sin(t) - 21)*e^(-2*t),where,ymin=x1,ymax=x2,color='gray',gridlines=True)                     #Solución exacta.
#p+=plot(z[0],where,gridlines=True)
for i in range(1,N+1):
    p+=plot(z[i],where,ymin=x1,ymax=x2,color=c[i])

show(p)
44
8tcos(t)+5-8 \, t - \cos\left(t\right) + 5
8t210tcos(t)+2sin(t)+58 \, t^{2} - 10 \, t - \cos\left(t\right) + 2 \, \sin\left(t\right) + 5
163t3+10t210t+3cos(t)+2sin(t)+1-\frac{16}{3} \, t^{3} + 10 \, t^{2} - 10 \, t + 3 \, \cos\left(t\right) + 2 \, \sin\left(t\right) + 1
83t4203t3+10t22t+3cos(t)6sin(t)+1\frac{8}{3} \, t^{4} - \frac{20}{3} \, t^{3} + 10 \, t^{2} - 2 \, t + 3 \, \cos\left(t\right) - 6 \, \sin\left(t\right) + 1
1615t5+103t4203t3+2t22t13cos(t)6sin(t)+17-\frac{16}{15} \, t^{5} + \frac{10}{3} \, t^{4} - \frac{20}{3} \, t^{3} + 2 \, t^{2} - 2 \, t - 13 \, \cos\left(t\right) - 6 \, \sin\left(t\right) + 17
1645t643t5+103t443t3+2t234t13cos(t)+26sin(t)+17\frac{16}{45} \, t^{6} - \frac{4}{3} \, t^{5} + \frac{10}{3} \, t^{4} - \frac{4}{3} \, t^{3} + 2 \, t^{2} - 34 \, t - 13 \, \cos\left(t\right) + 26 \, \sin\left(t\right) + 17
32315t7+49t643t5+23t443t3+34t234t+51cos(t)+26sin(t)47-\frac{32}{315} \, t^{7} + \frac{4}{9} \, t^{6} - \frac{4}{3} \, t^{5} + \frac{2}{3} \, t^{4} - \frac{4}{3} \, t^{3} + 34 \, t^{2} - 34 \, t + 51 \, \cos\left(t\right) + 26 \, \sin\left(t\right) - 47
8315t8863t7+49t6415t5+23t4683t3+34t2+94t+51cos(t)102sin(t)47\frac{8}{315} \, t^{8} - \frac{8}{63} \, t^{7} + \frac{4}{9} \, t^{6} - \frac{4}{15} \, t^{5} + \frac{2}{3} \, t^{4} - \frac{68}{3} \, t^{3} + 34 \, t^{2} + 94 \, t + 51 \, \cos\left(t\right) - 102 \, \sin\left(t\right) - 47
162835t9+263t8863t7+445t6415t5+343t4683t394t2+94t205cos(t)102sin(t)+209-\frac{16}{2835} \, t^{9} + \frac{2}{63} \, t^{8} - \frac{8}{63} \, t^{7} + \frac{4}{45} \, t^{6} - \frac{4}{15} \, t^{5} + \frac{34}{3} \, t^{4} - \frac{68}{3} \, t^{3} - 94 \, t^{2} + 94 \, t - 205 \, \cos\left(t\right) - 102 \, \sin\left(t\right) + 209
1614175t104567t9+263t88315t7+445t66815t5+343t4+1883t394t2418t205cos(t)+410sin(t)+209\frac{16}{14175} \, t^{10} - \frac{4}{567} \, t^{9} + \frac{2}{63} \, t^{8} - \frac{8}{315} \, t^{7} + \frac{4}{45} \, t^{6} - \frac{68}{15} \, t^{5} + \frac{34}{3} \, t^{4} + \frac{188}{3} \, t^{3} - 94 \, t^{2} - 418 \, t - 205 \, \cos\left(t\right) + 410 \, \sin\left(t\right) + 209
32155925t11+42835t104567t9+2315t88315t7+6845t66815t5943t4+1883t3+418t2418t+819cos(t)+410sin(t)815-\frac{32}{155925} \, t^{11} + \frac{4}{2835} \, t^{10} - \frac{4}{567} \, t^{9} + \frac{2}{315} \, t^{8} - \frac{8}{315} \, t^{7} + \frac{68}{45} \, t^{6} - \frac{68}{15} \, t^{5} - \frac{94}{3} \, t^{4} + \frac{188}{3} \, t^{3} + 418 \, t^{2} - 418 \, t + 819 \, \cos\left(t\right) + 410 \, \sin\left(t\right) - 815
16467775t12831185t11+42835t1042835t9+2315t8136315t7+6845t6+18815t5943t48363t3+418t2+1630t+819cos(t)1638sin(t)815\frac{16}{467775} \, t^{12} - \frac{8}{31185} \, t^{11} + \frac{4}{2835} \, t^{10} - \frac{4}{2835} \, t^{9} + \frac{2}{315} \, t^{8} - \frac{136}{315} \, t^{7} + \frac{68}{45} \, t^{6} + \frac{188}{15} \, t^{5} - \frac{94}{3} \, t^{4} - \frac{836}{3} \, t^{3} + 418 \, t^{2} + 1630 \, t + 819 \, \cos\left(t\right) - 1638 \, \sin\left(t\right) - 815
326081075t13+493555t12831185t11+414175t1042835t9+34315t8136315t718845t6+18815t5+4183t48363t31630t2+1630t3277cos(t)1638sin(t)+3281-\frac{32}{6081075} \, t^{13} + \frac{4}{93555} \, t^{12} - \frac{8}{31185} \, t^{11} + \frac{4}{14175} \, t^{10} - \frac{4}{2835} \, t^{9} + \frac{34}{315} \, t^{8} - \frac{136}{315} \, t^{7} - \frac{188}{45} \, t^{6} + \frac{188}{15} \, t^{5} + \frac{418}{3} \, t^{4} - \frac{836}{3} \, t^{3} - 1630 \, t^{2} + 1630 \, t - 3277 \, \cos\left(t\right) - 1638 \, \sin\left(t\right) + 3281
3242567525t1481216215t13+493555t128155925t11+414175t10682835t9+34315t8+376315t718845t683615t5+4183t4+32603t31630t26562t3277cos(t)+6554sin(t)+3281\frac{32}{42567525} \, t^{14} - \frac{8}{1216215} \, t^{13} + \frac{4}{93555} \, t^{12} - \frac{8}{155925} \, t^{11} + \frac{4}{14175} \, t^{10} - \frac{68}{2835} \, t^{9} + \frac{34}{315} \, t^{8} + \frac{376}{315} \, t^{7} - \frac{188}{45} \, t^{6} - \frac{836}{15} \, t^{5} + \frac{418}{3} \, t^{4} + \frac{3260}{3} \, t^{3} - 1630 \, t^{2} - 6562 \, t - 3277 \, \cos\left(t\right) + 6554 \, \sin\left(t\right) + 3281
64638512875t15+88513505t1481216215t13+4467775t128155925t11+6814175t10682835t994315t8+376315t7+83645t683615t516303t4+32603t3+6562t26562t+13107cos(t)+6554sin(t)13103-\frac{64}{638512875} \, t^{15} + \frac{8}{8513505} \, t^{14} - \frac{8}{1216215} \, t^{13} + \frac{4}{467775} \, t^{12} - \frac{8}{155925} \, t^{11} + \frac{68}{14175} \, t^{10} - \frac{68}{2835} \, t^{9} - \frac{94}{315} \, t^{8} + \frac{376}{315} \, t^{7} + \frac{836}{45} \, t^{6} - \frac{836}{15} \, t^{5} - \frac{1630}{3} \, t^{4} + \frac{3260}{3} \, t^{3} + 6562 \, t^{2} - 6562 \, t + 13107 \, \cos\left(t\right) + 6554 \, \sin\left(t\right) - 13103
8638512875t1616127702575t15+88513505t1486081075t13+4467775t12136155925t11+6814175t10+1882835t994315t81672315t7+83645t6+6523t516303t4131243t3+6562t2+26206t+13107cos(t)26214sin(t)13103\frac{8}{638512875} \, t^{16} - \frac{16}{127702575} \, t^{15} + \frac{8}{8513505} \, t^{14} - \frac{8}{6081075} \, t^{13} + \frac{4}{467775} \, t^{12} - \frac{136}{155925} \, t^{11} + \frac{68}{14175} \, t^{10} + \frac{188}{2835} \, t^{9} - \frac{94}{315} \, t^{8} - \frac{1672}{315} \, t^{7} + \frac{836}{45} \, t^{6} + \frac{652}{3} \, t^{5} - \frac{1630}{3} \, t^{4} - \frac{13124}{3} \, t^{3} + 6562 \, t^{2} + 26206 \, t + 13107 \, \cos\left(t\right) - 26214 \, \sin\left(t\right) - 13103
1610854718875t17+2127702575t1616127702575t15+842567525t1486081075t13+68467775t12136155925t1118814175t10+1882835t9+418315t81672315t76529t6+6523t5+65623t4131243t326206t2+26206t52429cos(t)26214sin(t)+52433-\frac{16}{10854718875} \, t^{17} + \frac{2}{127702575} \, t^{16} - \frac{16}{127702575} \, t^{15} + \frac{8}{42567525} \, t^{14} - \frac{8}{6081075} \, t^{13} + \frac{68}{467775} \, t^{12} - \frac{136}{155925} \, t^{11} - \frac{188}{14175} \, t^{10} + \frac{188}{2835} \, t^{9} + \frac{418}{315} \, t^{8} - \frac{1672}{315} \, t^{7} - \frac{652}{9} \, t^{6} + \frac{652}{3} \, t^{5} + \frac{6562}{3} \, t^{4} - \frac{13124}{3} \, t^{3} - 26206 \, t^{2} + 26206 \, t - 52429 \, \cos\left(t\right) - 26214 \, \sin\left(t\right) + 52433
1697692469875t1842170943775t17+2127702575t1616638512875t15+842567525t141366081075t13+68467775t12+376155925t1118814175t108362835t9+418315t8+130463t76529t61312415t5+65623t4+524123t326206t2104866t52429cos(t)+104858sin(t)+52433\frac{16}{97692469875} \, t^{18} - \frac{4}{2170943775} \, t^{17} + \frac{2}{127702575} \, t^{16} - \frac{16}{638512875} \, t^{15} + \frac{8}{42567525} \, t^{14} - \frac{136}{6081075} \, t^{13} + \frac{68}{467775} \, t^{12} + \frac{376}{155925} \, t^{11} - \frac{188}{14175} \, t^{10} - \frac{836}{2835} \, t^{9} + \frac{418}{315} \, t^{8} + \frac{1304}{63} \, t^{7} - \frac{652}{9} \, t^{6} - \frac{13124}{15} \, t^{5} + \frac{6562}{3} \, t^{4} + \frac{52412}{3} \, t^{3} - 26206 \, t^{2} - 104866 \, t - 52429 \, \cos\left(t\right) + 104858 \, \sin\left(t\right) + 52433
321856156927625t19+419538493975t1842170943775t17+2638512875t1616638512875t15+13642567525t141366081075t13188467775t12+376155925t11+83614175t108362835t932663t8+130463t7+1312445t61312415t5262063t4+524123t3+104866t2104866t+209715cos(t)+104858sin(t)209711-\frac{32}{1856156927625} \, t^{19} + \frac{4}{19538493975} \, t^{18} - \frac{4}{2170943775} \, t^{17} + \frac{2}{638512875} \, t^{16} - \frac{16}{638512875} \, t^{15} + \frac{136}{42567525} \, t^{14} - \frac{136}{6081075} \, t^{13} - \frac{188}{467775} \, t^{12} + \frac{376}{155925} \, t^{11} + \frac{836}{14175} \, t^{10} - \frac{836}{2835} \, t^{9} - \frac{326}{63} \, t^{8} + \frac{1304}{63} \, t^{7} + \frac{13124}{45} \, t^{6} - \frac{13124}{15} \, t^{5} - \frac{26206}{3} \, t^{4} + \frac{52412}{3} \, t^{3} + 104866 \, t^{2} - 104866 \, t + 209715 \, \cos\left(t\right) + 104858 \, \sin\left(t\right) - 209711
169280784638125t208371231385525t19+419538493975t18410854718875t17+2638512875t16272638512875t15+13642567525t14+3766081075t13188467775t1215214175t11+83614175t10+652567t932663t826248315t7+1312445t6+5241215t5262063t42097323t3+104866t2+419422t+209715cos(t)419430sin(t)209711\frac{16}{9280784638125} \, t^{20} - \frac{8}{371231385525} \, t^{19} + \frac{4}{19538493975} \, t^{18} - \frac{4}{10854718875} \, t^{17} + \frac{2}{638512875} \, t^{16} - \frac{272}{638512875} \, t^{15} + \frac{136}{42567525} \, t^{14} + \frac{376}{6081075} \, t^{13} - \frac{188}{467775} \, t^{12} - \frac{152}{14175} \, t^{11} + \frac{836}{14175} \, t^{10} + \frac{652}{567} \, t^{9} - \frac{326}{63} \, t^{8} - \frac{26248}{315} \, t^{7} + \frac{13124}{45} \, t^{6} + \frac{52412}{15} \, t^{5} - \frac{26206}{3} \, t^{4} - \frac{209732}{3} \, t^{3} + 104866 \, t^{2} + 419422 \, t + 209715 \, \cos\left(t\right) - 419430 \, \sin\left(t\right) - 209711
32194896477400625t21+41856156927625t208371231385525t19+497692469875t18410854718875t17+34638512875t16272638512875t1537642567525t14+3766081075t13+7642525t1215214175t116522835t10+652567t9+6562315t826248315t75241245t6+5241215t5+1048663t42097323t3419422t2+419422t838861cos(t)419430sin(t)+838865-\frac{32}{194896477400625} \, t^{21} + \frac{4}{1856156927625} \, t^{20} - \frac{8}{371231385525} \, t^{19} + \frac{4}{97692469875} \, t^{18} - \frac{4}{10854718875} \, t^{17} + \frac{34}{638512875} \, t^{16} - \frac{272}{638512875} \, t^{15} - \frac{376}{42567525} \, t^{14} + \frac{376}{6081075} \, t^{13} + \frac{76}{42525} \, t^{12} - \frac{152}{14175} \, t^{11} - \frac{652}{2835} \, t^{10} + \frac{652}{567} \, t^{9} + \frac{6562}{315} \, t^{8} - \frac{26248}{315} \, t^{7} - \frac{52412}{45} \, t^{6} + \frac{52412}{15} \, t^{5} + \frac{104866}{3} \, t^{4} - \frac{209732}{3} \, t^{3} - 419422 \, t^{2} + 419422 \, t - 838861 \, \cos\left(t\right) - 419430 \, \sin\left(t\right) + 838865
322143861251406875t22838979295480125t21+41856156927625t2081856156927625t19+497692469875t184638512875t17+34638512875t16+752638512875t1537642567525t14152552825t13+7642525t12+130431185t116522835t10131242835t9+6562315t8+104824315t75241245t620973215t5+1048663t4+8388443t3419422t21677730t838861cos(t)+1677722sin(t)+838865\frac{32}{2143861251406875} \, t^{22} - \frac{8}{38979295480125} \, t^{21} + \frac{4}{1856156927625} \, t^{20} - \frac{8}{1856156927625} \, t^{19} + \frac{4}{97692469875} \, t^{18} - \frac{4}{638512875} \, t^{17} + \frac{34}{638512875} \, t^{16} + \frac{752}{638512875} \, t^{15} - \frac{376}{42567525} \, t^{14} - \frac{152}{552825} \, t^{13} + \frac{76}{42525} \, t^{12} + \frac{1304}{31185} \, t^{11} - \frac{652}{2835} \, t^{10} - \frac{13124}{2835} \, t^{9} + \frac{6562}{315} \, t^{8} + \frac{104824}{315} \, t^{7} - \frac{52412}{45} \, t^{6} - \frac{209732}{15} \, t^{5} + \frac{104866}{3} \, t^{4} + \frac{838844}{3} \, t^{3} - 419422 \, t^{2} - 1677730 \, t - 838861 \, \cos\left(t\right) + 1677722 \, \sin\left(t\right) + 838865
6449308808782358125t23+8428772250281375t22838979295480125t21+49280784638125t2081856156927625t19+45746615875t184638512875t1794638512875t16+752638512875t15+1523869775t14152552825t1365293555t12+130431185t11+1312414175t10131242835t926206315t8+104824315t7+20973245t620973215t54194223t4+8388443t3+1677730t21677730t+3355443cos(t)+1677722sin(t)3355439-\frac{64}{49308808782358125} \, t^{23} + \frac{8}{428772250281375} \, t^{22} - \frac{8}{38979295480125} \, t^{21} + \frac{4}{9280784638125} \, t^{20} - \frac{8}{1856156927625} \, t^{19} + \frac{4}{5746615875} \, t^{18} - \frac{4}{638512875} \, t^{17} - \frac{94}{638512875} \, t^{16} + \frac{752}{638512875} \, t^{15} + \frac{152}{3869775} \, t^{14} - \frac{152}{552825} \, t^{13} - \frac{652}{93555} \, t^{12} + \frac{1304}{31185} \, t^{11} + \frac{13124}{14175} \, t^{10} - \frac{13124}{2835} \, t^{9} - \frac{26206}{315} \, t^{8} + \frac{104824}{315} \, t^{7} + \frac{209732}{45} \, t^{6} - \frac{209732}{15} \, t^{5} - \frac{419422}{3} \, t^{4} + \frac{838844}{3} \, t^{3} + 1677730 \, t^{2} - 1677730 \, t + 3355443 \, \cos\left(t\right) + 1677722 \, \sin\left(t\right) - 3355439
16147926426347074375t24169861761756471625t23+8428772250281375t228194896477400625t21+49280784638125t208109185701625t19+45746615875t18+18810854718875t1794638512875t1630458046625t15+1523869775t14+13041216215t1365293555t1226248155925t11+1312414175t10+524122835t926206315t8419464315t7+20973245t6+83884415t54194223t433554603t3+1677730t2+6710878t+3355443cos(t)6710886sin(t)3355439\frac{16}{147926426347074375} \, t^{24} - \frac{16}{9861761756471625} \, t^{23} + \frac{8}{428772250281375} \, t^{22} - \frac{8}{194896477400625} \, t^{21} + \frac{4}{9280784638125} \, t^{20} - \frac{8}{109185701625} \, t^{19} + \frac{4}{5746615875} \, t^{18} + \frac{188}{10854718875} \, t^{17} - \frac{94}{638512875} \, t^{16} - \frac{304}{58046625} \, t^{15} + \frac{152}{3869775} \, t^{14} + \frac{1304}{1216215} \, t^{13} - \frac{652}{93555} \, t^{12} - \frac{26248}{155925} \, t^{11} + \frac{13124}{14175} \, t^{10} + \frac{52412}{2835} \, t^{9} - \frac{26206}{315} \, t^{8} - \frac{419464}{315} \, t^{7} + \frac{209732}{45} \, t^{6} + \frac{838844}{15} \, t^{5} - \frac{419422}{3} \, t^{4} - \frac{3355460}{3} \, t^{3} + 1677730 \, t^{2} + 6710878 \, t + 3355443 \, \cos\left(t\right) - 6710886 \, \sin\left(t\right) - 3355439
323698160658676859375t25+429585285269414875t24169861761756471625t23+82143861251406875t228194896477400625t21+4545928508125t208109185701625t1918897692469875t18+18810854718875t17+3858046625t1630458046625t1513048513505t14+13041216215t13+13124467775t1226248155925t115241214175t10+524122835t9+104866315t8419464315t783884445t6+83884415t5+16777303t433554603t36710878t2+6710878t13421773cos(t)6710886sin(t)+13421777-\frac{32}{3698160658676859375} \, t^{25} + \frac{4}{29585285269414875} \, t^{24} - \frac{16}{9861761756471625} \, t^{23} + \frac{8}{2143861251406875} \, t^{22} - \frac{8}{194896477400625} \, t^{21} + \frac{4}{545928508125} \, t^{20} - \frac{8}{109185701625} \, t^{19} - \frac{188}{97692469875} \, t^{18} + \frac{188}{10854718875} \, t^{17} + \frac{38}{58046625} \, t^{16} - \frac{304}{58046625} \, t^{15} - \frac{1304}{8513505} \, t^{14} + \frac{1304}{1216215} \, t^{13} + \frac{13124}{467775} \, t^{12} - \frac{26248}{155925} \, t^{11} - \frac{52412}{14175} \, t^{10} + \frac{52412}{2835} \, t^{9} + \frac{104866}{315} \, t^{8} - \frac{419464}{315} \, t^{7} - \frac{838844}{45} \, t^{6} + \frac{838844}{15} \, t^{5} + \frac{1677730}{3} \, t^{4} - \frac{3355460}{3} \, t^{3} - 6710878 \, t^{2} + 6710878 \, t - 13421773 \, \cos\left(t\right) - 6710886 \, \sin\left(t\right) + 13421777
3248076088562799171875t268739632131735371875t25+429585285269414875t241649308808782358125t23+82143861251406875t22811464498670625t21+4545928508125t20+3761856156927625t1918897692469875t1876986792625t17+3858046625t16+2608127702575t1513048513505t14262486081075t13+13124467775t12+104824155925t115241214175t102097322835t9+104866315t8+1677688315t783884445t66710923t5+16777303t4+134217563t36710878t226843554t13421773cos(t)+26843546sin(t)+13421777\frac{32}{48076088562799171875} \, t^{26} - \frac{8}{739632131735371875} \, t^{25} + \frac{4}{29585285269414875} \, t^{24} - \frac{16}{49308808782358125} \, t^{23} + \frac{8}{2143861251406875} \, t^{22} - \frac{8}{11464498670625} \, t^{21} + \frac{4}{545928508125} \, t^{20} + \frac{376}{1856156927625} \, t^{19} - \frac{188}{97692469875} \, t^{18} - \frac{76}{986792625} \, t^{17} + \frac{38}{58046625} \, t^{16} + \frac{2608}{127702575} \, t^{15} - \frac{1304}{8513505} \, t^{14} - \frac{26248}{6081075} \, t^{13} + \frac{13124}{467775} \, t^{12} + \frac{104824}{155925} \, t^{11} - \frac{52412}{14175} \, t^{10} - \frac{209732}{2835} \, t^{9} + \frac{104866}{315} \, t^{8} + \frac{1677688}{315} \, t^{7} - \frac{838844}{45} \, t^{6} - \frac{671092}{3} \, t^{5} + \frac{1677730}{3} \, t^{4} + \frac{13421756}{3} \, t^{3} - 6710878 \, t^{2} - 26843554 \, t - 13421773 \, \cos\left(t\right) + 26843546 \, \sin\left(t\right) + 13421777
641298054391195577640625t27+89615217712559834375t268739632131735371875t25+4147926426347074375t241649308808782358125t23+8126109485376875t22811464498670625t211889280784638125t20+3761856156927625t19+768881133625t1876986792625t17326127702575t16+2608127702575t15+2624842567525t14262486081075t1352412467775t12+104824155925t11+20973214175t102097322835t9419422315t8+1677688315t7+6710929t66710923t567108783t4+134217563t3+26843554t226843554t+53687091cos(t)+26843546sin(t)53687087-\frac{64}{1298054391195577640625} \, t^{27} + \frac{8}{9615217712559834375} \, t^{26} - \frac{8}{739632131735371875} \, t^{25} + \frac{4}{147926426347074375} \, t^{24} - \frac{16}{49308808782358125} \, t^{23} + \frac{8}{126109485376875} \, t^{22} - \frac{8}{11464498670625} \, t^{21} - \frac{188}{9280784638125} \, t^{20} + \frac{376}{1856156927625} \, t^{19} + \frac{76}{8881133625} \, t^{18} - \frac{76}{986792625} \, t^{17} - \frac{326}{127702575} \, t^{16} + \frac{2608}{127702575} \, t^{15} + \frac{26248}{42567525} \, t^{14} - \frac{26248}{6081075} \, t^{13} - \frac{52412}{467775} \, t^{12} + \frac{104824}{155925} \, t^{11} + \frac{209732}{14175} \, t^{10} - \frac{209732}{2835} \, t^{9} - \frac{419422}{315} \, t^{8} + \frac{1677688}{315} \, t^{7} + \frac{671092}{9} \, t^{6} - \frac{671092}{3} \, t^{5} - \frac{6710878}{3} \, t^{4} + \frac{13421756}{3} \, t^{3} + 26843554 \, t^{2} - 26843554 \, t + 53687091 \, \cos\left(t\right) + 26843546 \, \sin\left(t\right) - 53687087
329086380738369043484375t2816259610878239115528125t27+89615217712559834375t2683698160658676859375t25+4147926426347074375t24162900518163668125t23+8126109485376875t22+376194896477400625t211889280784638125t2088881133625t19+768881133625t18+6522170943775t17326127702575t1652496638512875t15+2624842567525t14+1048246081075t1352412467775t12419464155925t11+20973214175t10+8388442835t9419422315t8134218463t7+6710929t6+1342175615t567108783t4536871083t3+26843554t2+107374174t+53687091cos(t)107374182sin(t)53687087\frac{32}{9086380738369043484375} \, t^{28} - \frac{16}{259610878239115528125} \, t^{27} + \frac{8}{9615217712559834375} \, t^{26} - \frac{8}{3698160658676859375} \, t^{25} + \frac{4}{147926426347074375} \, t^{24} - \frac{16}{2900518163668125} \, t^{23} + \frac{8}{126109485376875} \, t^{22} + \frac{376}{194896477400625} \, t^{21} - \frac{188}{9280784638125} \, t^{20} - \frac{8}{8881133625} \, t^{19} + \frac{76}{8881133625} \, t^{18} + \frac{652}{2170943775} \, t^{17} - \frac{326}{127702575} \, t^{16} - \frac{52496}{638512875} \, t^{15} + \frac{26248}{42567525} \, t^{14} + \frac{104824}{6081075} \, t^{13} - \frac{52412}{467775} \, t^{12} - \frac{419464}{155925} \, t^{11} + \frac{209732}{14175} \, t^{10} + \frac{838844}{2835} \, t^{9} - \frac{419422}{315} \, t^{8} - \frac{1342184}{63} \, t^{7} + \frac{671092}{9} \, t^{6} + \frac{13421756}{15} \, t^{5} - \frac{6710878}{3} \, t^{4} - \frac{53687108}{3} \, t^{3} + 26843554 \, t^{2} + 107374174 \, t + 53687091 \, \cos\left(t\right) - 107374182 \, \sin\left(t\right) - 53687087
WARNING: Some output was deleted.
N=50;b=1
from sage.plot.colors import rainbow
c=rainbow(N+1)
where = [x,0,b]
p=plot(x^0,where,color='gray',gridlines=True)
for i in range(1,N+1):
    p+=plot(x^i,where,color=c[i])
show(p)
x = var('x')
y = function('y')(x)
show(desolve(diff(y,x) - exp(x+y), y))
(e(x+y(x))+1)e(y(x))=C-{\left(e^{\left(x + y\left(x\right)\right)} + 1\right)} e^{\left(-y\left(x\right)\right)} = C
x = var('x')
y = function('y')(x)
f = desolve(diff(y,x) -exp(x+y), y, ics=[0,1]); show(f)
(e(x+y(x))+1)e(y(x))=(e+1)e(1)-{\left(e^{\left(x + y\left(x\right)\right)} + 1\right)} e^{\left(-y\left(x\right)\right)} = -{\left(e + 1\right)} e^{\left(-1\right)}
t = var('t')
x = function('x')(t)
f = desolve(diff(x,t) -sin(t) + 2*x, x, ics=[0,4]); f
-1/5*(cos(t)*e^(2*t) - 2*e^(2*t)*sin(t) - 21)*e^(-2*t)
t = var('t')
x = function('x')(t)
f = desolve(diff(x,t) -sin(t) + 2*x, x, ics=[0,4]); show(f)
15(cos(t)e(2t)2e(2t)sin(t)21)e(2t)-\frac{1}{5} \, {\left(\cos\left(t\right) e^{\left(2 \, t\right)} - 2 \, e^{\left(2 \, t\right)} \sin\left(t\right) - 21\right)} e^{\left(-2 \, t\right)}
def picard_iteration(f, a, c, N):
    '''
    Computes the N-th Picard iterate for the IVP  

        x' = f(t,x), x(a) = c.

    EXAMPLES:
        sage: var('x t s')
        (x, t, s)
        sage: a = 0; c = 2
        sage: f = lambda t,x: 1-x
        sage: picard_iteration(f, a, c, 0)
        2
         sage: picard_iteration(f, a, c, 1)
        2 - t
        sage: picard_iteration(f, a, c, 2)
        t^2/2 - t + 2
        sage: picard_iteration(f, a, c, 3)
        -t^3/6 + t^2/2 - t + 2
        sage: var('x t s')
        (x, t, s)
        sage: a = 0; c = 2
        sage: f = lambda t,x: (x+t)^2
        sage: picard_iteration(f, a, c, 0)
        2
        sage: picard_iteration(f, a, c, 1)
        t^3/3 + 2*t^2 + 4*t + 2
        sage: picard_iteration(f, a, c, 2)
        t^7/63 + 2*t^6/9 + 22*t^5/15 + 16*t^4/3 + 11*t^3 + 10*t^2 + 4*t + 2

    '''
    if N == 0:
        return c*t**0
    if N == 1:
        #print integral(f(s,c*s**0), s, a, t)
        assume(s>0) 
        x0 = lambda t: c + integral(f(s,c*s**0), s, a, t)
        return expand(x0(t))
    for i in range(N):
        x_old = lambda s: picard_iteration(f, a, c, N-1).subs(t=s)
        #print x_old(s)
        x0 = lambda t: c + integral(f(s,x_old(s)), s, a, t)
    return expand(x0(t))
v=var('x t s')
a = 0; c = 1; N=2; b=.5;
f = lambda t,x: exp(x+t); assume(t>0) 
z=[picard_iteration(f, a, c, i) for i in range(N+1)]
for i in range(N+1):
    show(z[i])
from sage.plot.colors import rainbow
c=rainbow(N+1)
where = [x,-b,b]
p=plot(-log(abs(-1-exp(-1)+exp(t))),where,color='gray',gridlines=True)                     #Solución exacta.
#p+=plot(z[0],where,gridlines=True)
for i in range(N+1):
    p+=plot(z[i],where,color=c[i])

show(p)
11
e+e(t+1)+1-e + e^{\left(t + 1\right)} + 1
e(e+e(t+1))e^{\left(-e + e^{\left(t + 1\right)}\right)}