Question: What could be wrong with this code?

I am trying to run this code but this error message is coming up "Error, (in fprintf) number expected for floating point format
". What have I done wrong and how do I correct it.

Thank you and best regards.

 

restart;
Digits:=30:

f:=proc(n)
	-((sin(x[n]))/(2-sin(x[n])))*(2+sin(x[n]-Pi)):
end proc:

e1:=y[n+1]=h*delta[n]-(1/2)*h^2*(-u^2*sin((1/2)*u)+2*cos((1/2)*u)*u-2*cos(u)*u-4*sin((1/2)*u)+2*sin(u))*f(n)/(u^2*(2*sin((1/2)*u)-sin(u)))+(1/2)*h^2*(u^2*sin((1/2)*u)+2*cos((1/2)*u)*u-4*sin((1/2)*u)+2*sin(u)-2*u)*f(n+1)/(u^2*(2*sin((1/2)*u)-sin(u)))-(1/2)*h^2*(u*sin(u)+2*cos(u)-2)*f(n+1/2)/(u*(2*sin((1/2)*u)-sin(u)))+y[n]:
e2:=h*delta[n+1]=h*delta[n]+h^2*(u*sin((1/2)*u)+cos(u)-1)*f(n)/(u*(2*sin((1/2)*u)-sin(u)))+h^2*(u*sin((1/2)*u)+cos(u)-1)*f(n+1)/(u*(2*sin((1/2)*u)-sin(u)))-h^2*(u*sin(u)+2*cos(u)-2)*f(n+1/2)/(u*(2*sin((1/2)*u)-sin(u))):
e3:=y[n+1/2]=(1/2)*h*delta[n]-(1/8)*h^2*(-u^2*sin((1/2)*u)+4*cos((1/2)*u)*u-4*cos(u)*u-16*sin((1/2)*u)+8*sin(u))*f(n)/(u^2*(2*sin((1/2)*u)-sin(u)))+(1/8)*h^2*(u*sin((1/2)*u)+4*cos((1/2)*u)-4)*f(n+1)/(u*(2*sin((1/2)*u)-sin(u)))-(1/8)*h^2*(u^2*sin(u)+4*cos(u)*u+16*sin((1/2)*u)-8*sin(u)-4*u)*f(n+1/2)/(u^2*(2*sin((1/2)*u)-sin(u)))+y[n]:
e4:=h*delta[n+1/2]=h*delta[n]-(1/2)*h^2*(-u*sin((1/2)*u)+4*cos((1/2)*u)-2*cos(u)-2)*f(n)/(u*(2*sin((1/2)*u)-sin(u)))+(1/2)*h^2*(u*sin((1/2)*u)+4*cos((1/2)*u)-4)*f(n+1)/(u*(2*sin((1/2)*u)-sin(u)))-(1/2)*h^2*(u*sin(u)+2*cos(u)-2)*f(n+1/2)/(u*(2*sin((1/2)*u)-sin(u))):


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

c:=1:
for j from 0 to 1 by 1/2 do
	t[j]:=inx+j*h:
end do:

vars:=y[n+1/2],y[n+1],delta[n+1/2],delta[n+1]:

step := [seq](eval(x, x=c*h), c=1..N):
printf("%6s%15s%15s%16s%15s%15s%15s\n", 
	"h","Num.y","Num.z","Ex.y","Ex.z","Error y","Error z");
#eval(<vars>, solve({e||(1..4)},{vars}));


st := time():
for k from 1 to N do

	par1:=x[0]=t[0],x[1/2]=t[1/2],x[1]=t[1]:
	par2:=y[n]=iny,delta[n]=ind:
	res:=eval(<vars>, fsolve(eval({e||(1..4)},[par1,par2]), {vars}));

	for i from 1 to 2 do
		exy:=eval(2+sin(c*h/2)):
		exz:=eval(-sin(c*h/2)+10*epsilon*cos(10*c*h)):
		printf("%6.5f%17.9f%15.9f%15.9f%15.9f %13.5g%15.5g\n", 
		h*c,res[i],res[i+2],exy,exz,abs(res[i]-exy),
		abs(res[i+2]-exz)):
		
		c:=c+1:

	end do:
	iny:=res[2]:
	ind:=res[4]:
	inx:=t[1]:
	for j from 0 to 1 by 1/2 do
		t[j]:=inx + j*h:
	end do:
end do:

 

Please Wait...