Question: Code Correction

Please I am having problem with this code particularly the last subroutine

#subroutine 1

restart;
Digits:=30:

f:=proc(n)
    -25*y[n]+12*cos(x[n]):
end proc:

#subroutine 2

e1:=y[n+4] = -y[n]+2*y[n+2]+((1/15)*h^2+(2/945)*h^2*u^2+(1/56700)*h^2*u^4-(1/415800)*h^2*u^6-(167/833976000)*h^2*u^8-(2633/245188944000)*h^2*u^10-(2671/5557616064000)*h^2*u^12-(257857/13304932857216000)*h^2*u^14-(3073333/4215002729166028800)*h^2*u^16)*f(n)+((16/15)*h^2-(8/945)*h^2*u^2-(1/14175)*h^2*u^4+(1/103950)*h^2*u^6+(167/208494000)*h^2*u^8+(2633/61297236000)*h^2*u^10+(2671/1389404016000)*h^2*u^12+(257857/3326233214304000)*h^2*u^14+(3073333/1053750682291507200)*h^2*u^16)*f(n+1)+((26/15)*h^2+(4/315)*h^2*u^2+(1/9450)*h^2*u^4-(1/69300)*h^2*u^6-(167/138996000)*h^2*u^8-(2633/40864824000)*h^2*u^10-(2671/926269344000)*h^2*u^12-(257857/2217488809536000)*h^2*u^14-(3073333/702500454861004800)*h^2*u^16)*f(n+2)+((16/15)*h^2-(8/945)*h^2*u^2-(1/14175)*h^2*u^4+(1/103950)*h^2*u^6+(167/208494000)*h^2*u^8+(2633/61297236000)*h^2*u^10+(2671/1389404016000)*h^2*u^12+(257857/3326233214304000)*h^2*u^14+(3073333/1053750682291507200)*h^2*u^16)*f(n+3)+((1/15)*h^2+(2/945)*h^2*u^2+(1/56700)*h^2*u^4-(1/415800)*h^2*u^6-(167/833976000)*h^2*u^8-(2633/245188944000)*h^2*u^10-(2671/5557616064000)*h^2*u^12-(257857/13304932857216000)*h^2*u^14-(3073333/4215002729166028800)*h^2*u^16)*f(n+4):

e2:=y[n+3] = -y[n+1]+2*y[n+2]+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(n)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(n+1)+((97/120)*h^2-(31/10080)*h^2*u^2-(67/302400)*h^2*u^4-(109/8870400)*h^2*u^6-(18127/31135104000)*h^2*u^8-(64931/2615348736000)*h^2*u^10-(9701/9880206336000)*h^2*u^12-(20832397/567677135241216000)*h^2*u^14-(11349439/8646159444443136000)*h^2*u^16)*f(n+2)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(n+3)+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(n+4):

e3:=h*delta[n] = (-149/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[n]+(128/21+(32/245)*u^2+(2648/169785)*u^4+(1118492/695269575)*u^6+(14310311/87603966450)*u^8+(170868550903/10320623287474500)*u^10)*y[n+1]+(-107/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[n+2]+(-(67/1260)*h^2+(1241/198450)*h^2*u^2+(277961/366735600)*h^2*u^4+(26460409/333729396000)*h^2*u^6+(1363374533/168199615584000)*h^2*u^8+(16323847966961/19815596711951040000)*h^2*u^10)*f(n)+((188/105)*h^2+(5078/99225)*h^2*u^2+(556159/91683900)*h^2*u^4+(51834031/83432349000)*h^2*u^6+(67782373/1078202664000)*h^2*u^8+(1854079193287/291405833999280000)*h^2*u^10)*f(n+1)+((31/90)*h^2+(341/33075)*h^2*u^2+(79361/61122600)*h^2*u^4+(23456627/166864698000)*h^2*u^6+(1228061399/84099807792000)*h^2*u^8+(14797833720283/9907798355975520000)*h^2*u^10)*f(n+2)+(-(4/105)*h^2-(46/14175)*h^2*u^2-(809/1871100)*h^2*u^4-(27827/567567000)*h^2*u^6-(637171/122594472000)*h^2*u^8-(33500737/62523180720000)*h^2*u^10)*f(n+3)+((1/252)*h^2+(23/28350)*h^2*u^2+(809/7484400)*h^2*u^4+(27827/2270268000)*h^2*u^6+(637171/490377888000)*h^2*u^8+(33500737/250092722880000)*h^2*u^10)*f(n+4):

e4:=y[3] = -y[1]+2*y[2]+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(0)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(1)+((97/120)*h^2-(31/10080)*h^2*u^2-(67/302400)*h^2*u^4-(109/8870400)*h^2*u^6-(18127/31135104000)*h^2*u^8-(64931/2615348736000)*h^2*u^10-(9701/9880206336000)*h^2*u^12-(20832397/567677135241216000)*h^2*u^14-(11349439/8646159444443136000)*h^2*u^16)*f(2)+((1/10)*h^2+(31/15120)*h^2*u^2+(67/453600)*h^2*u^4+(109/13305600)*h^2*u^6+(18127/46702656000)*h^2*u^8+(64931/3923023104000)*h^2*u^10+(9701/14820309504000)*h^2*u^12+(20832397/851515702861824000)*h^2*u^14+(11349439/12969239166664704000)*h^2*u^16)*f(3)+(-(1/240)*h^2-(31/60480)*h^2*u^2-(67/1814400)*h^2*u^4-(109/53222400)*h^2*u^6-(18127/186810624000)*h^2*u^8-(64931/15692092416000)*h^2*u^10-(9701/59281238016000)*h^2*u^12-(20832397/3406062811447296000)*h^2*u^14-(11349439/51876956666658816000)*h^2*u^16)*f(4):

e5:=h*delta[0] = (-149/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[0]+(128/21+(32/245)*u^2+(2648/169785)*u^4+(1118492/695269575)*u^6+(14310311/87603966450)*u^8+(170868550903/10320623287474500)*u^10)*y[1]+(-107/42-(16/245)*u^2-(1324/169785)*u^4-(559246/695269575)*u^6-(14310311/175207932900)*u^8-(170868550903/20641246574949000)*u^10)*y[2]+(-(67/1260)*h^2+(1241/198450)*h^2*u^2+(277961/366735600)*h^2*u^4+(26460409/333729396000)*h^2*u^6+(1363374533/168199615584000)*h^2*u^8+(16323847966961/19815596711951040000)*h^2*u^10)*f(0)+((188/105)*h^2+(5078/99225)*h^2*u^2+(556159/91683900)*h^2*u^4+(51834031/83432349000)*h^2*u^6+(67782373/1078202664000)*h^2*u^8+(1854079193287/291405833999280000)*h^2*u^10)*f(1)+((31/90)*h^2+(341/33075)*h^2*u^2+(79361/61122600)*h^2*u^4+(23456627/166864698000)*h^2*u^6+(1228061399/84099807792000)*h^2*u^8+(14797833720283/9907798355975520000)*h^2*u^10)*f(2)+(-(4/105)*h^2-(46/14175)*h^2*u^2-(809/1871100)*h^2*u^4-(27827/567567000)*h^2*u^6-(637171/122594472000)*h^2*u^8-(33500737/62523180720000)*h^2*u^10)*f(3)+((1/252)*h^2+(23/28350)*h^2*u^2+(809/7484400)*h^2*u^4+(27827/2270268000)*h^2*u^6+(637171/490377888000)*h^2*u^8+(33500737/250092722880000)*h^2*u^10)*f(4):

 

#subroutine 3

 


inx:=0:
ind:=0:
iny:=1:
h:=Pi/4.0:
n:=0:
omega:=5:
u:=omega*h:
N:=solve(h*p = 500*Pi/2, p):

c:=1:
for j from 0 to 5 do
    t[j]:=inx+j*h:
end do:
#e||(1..6);
vars:=y[n+1],y[n+2],y[n+3],delta[n],y[n+4]:

printf("%6s%15s%15s%15s\n",
    "h","Num.y","Ex.y","Error y");
for k from 1 to N do

    par1:=x[0]=t[0],x[1]=t[1],x[2]=t[2],x[3]=t[3],x[4]=t[4],x[5]=t[5]:
    par2:=y[n]=iny,delta[n]=ind:
   

res:=eval(<vars>, fsolve(eval({e||(1..5)},[par1,par2]), {vars}));

    for i from 1 to 5 do
        exy:=eval(0.5*cos(5*c*h)+0.5*cos(c*h)):
        printf("%6.5f%17.9f%15.9f%13.5g\n",
        h*c,res[i],exy,abs(res[i]-exy)):
        
        c:=c+1:
    end do:
    iny:=res[5]:
    inx:=t[5]:
    for j from 0 to 5 do
        t[j]:=inx + j*h:
    end do:
end do:

 

 

 

 

Please Wait...