abdulganiy

145 Reputation

6 Badges

9 years, 91 days

MaplePrimes Activity


These are questions asked by abdulganiy

Good day, all. I hope we are staying safe.

Please I need help with the regard to the following codes.

The major issue is with rho:=x[n]/h. The rho needs to change values as x[n] changes in the computation. This I think I have gotten wrong. Your professional modifications or/and corrections to the code would be appreciated.

Thank you and kind regards.

restart;
Digits:=20:
#assume(alpha>0,alpha < 1):
f:=proc(n)
	-y[n]-x[n]+(x[n])^2+(2*(x[n])^(2-alpha))/GAMMA(3-alpha)+((x[n])^(1-alpha))/GAMMA(2-alpha):
end proc:

e2:=y[n+2] = y[n]+(1/2)*((alpha^2-alpha)*rho^2+(2*alpha^2-2)*rho+(4/3)*alpha^2-(2/3)*alpha)*(rho*h)^alpha*GAMMA(2-alpha)*f(n)/rho-alpha*GAMMA(2-alpha)*((-1+alpha)*rho^2+(2*alpha-2)*rho+(4/3)*alpha-8/3)*(h*(rho+1))^alpha*f(n+1)/(rho+1)+(1/2)*((alpha^2-alpha)*rho^2+2*(-1+alpha)^2*rho+(4/3)*alpha^2-(14/3)*alpha+4)*(h*(rho+2))^alpha*f(n+2)*GAMMA(2-alpha)/(rho+2):
e1:=y[n+1] = y[n]+(1/4)*((alpha^2-alpha)*rho^2+(alpha^2+3*alpha-4)*rho+(1/3)*alpha^2+(4/3)*alpha)*GAMMA(2-alpha)*f(n)/((rho*h)^(-alpha)*rho)-(1/2)*GAMMA(2-alpha)*((alpha^2-alpha)*rho^2+(alpha^2+alpha-2)*rho+(1/3)*alpha^2+(1/3)*alpha-2)*f(n+1)/((h*(rho+1))^(-alpha)*(rho+1))+(1/4)*((-1+alpha)*rho^2+(-1+alpha)*rho+(1/3)*alpha-2/3)*alpha*GAMMA(2-alpha)*f(n+2)/((h*(rho+2))^(-alpha)*(rho+2)):


alpha:=0.25:
inx:=0:
iny:=0:
#x[0]:=0:
h:=1/20:
N:=solve(h*p = 1, p):
n:=0:
c:=1:
rho:=x[n]/h: 
err := Vector(round(N)):
exy_lst := Vector(round(N)):

for j from 0 to 2 do
	t[j]:=inx+j*h:
end do:
vars:=y[n+1],y[n+2]:

step := [seq](eval(x, x=c*h), c=1..N):

printf("%4s%15s%15s%16s\n", 
	"h","Num.y","Ex.y","Error y");
st := time():
for k from 1 to N/2 do

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

	for i from 1 to 2 do
		exy:=eval(-c*h+(c*h)^2):
		printf("%5.3f%17.9f%15.9f%15.5g\n", 
		h*c,res[i],exy,abs(res[i]-exy)):
		
		err[c] := abs(evalf(res[i]-exy)):
		exy_lst[c] := exy:
		numerical_y1[c] := res[i]:
		c:=c+1:
		rho:=rho+1:
	end do:
	iny:=res[2]:
	inx:=t[2]:
	for j from 0 to 2 do
		t[j]:=inx + j*h:
	end do:
end do:
v:=time() - st;
printf("Maximum error is %.13g\n", max(err));

numerical_array_y1 := [seq(numerical_y1[i], i = 1 .. N)]:

time_t := [seq](step[i], i = 1 .. N):

with(plots):
numerical_plot_y1 := plot(time_t, numerical_array_y1, style = [point], symbol = [asterisk],
				color = [blue,blue],symbolsize = 15, title="y numerical",legend = ["Numerical"]);
exact_plot_y1 := plot(time_t, exy_lst, style = [line], symbol = [box], 
				color = [red,red], symbolsize = 10, title="y exact",legend = ["Exact"]);

display({numerical_plot_y1, exact_plot_y1}, title = "Exact and Numerical Solution of Example 1 ");

 

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:

 

In this code, there are 8 vectors, each vector has 5 points except vectors 7 and 8 with 4 points. I made their  (7 and 8) respective fifth point a string. However, this error statement pops up "Error, invalid input: log[10] expects its 1st argument, x, to be of type algebraic, but received 2.51E-10".

Can someone help me with the correction?

Thank you all and kind regards

 

restart;

B:=<<601,1201,2401,4801,9601>|<2.87E-19,7.94E-21,7.94E-23,1.03E-24,5.91E-26>|
    <2001,4001,8001,16001,32001>|<3.30E-2,5.37E-4,8.47E-6,1.33E-7,2.08E-9>|
    <183,365,728,1476,2910>|<4.58E0,7.54E-8,2.20E-11,4.95E-14,9.15E-15>|
    <1621,3020,6166,12022,"2222">|<2.95E-3,8.51E-6,3.39E-8,2.51E-10,"2.51E-10">>:

for i from 1 to 5 do
   B[i, 2] := log[10](B[i, 2]):                      
   B[i, 4] := log[10](B[i, 4]):         
   B[i, 6] := log[10](B[i, 6]):         
   B[i, 8] := log[10](B[i, 8]):

   B[i, 1] := log[10](B[i, 1]):                      
   B[i, 3] := log[10](B[i, 3]):         
   B[i, 5] := log[10](B[i, 5]):         
   B[i, 7] := log[10](B[i, 7]):

end do:  # computing the log of the max-error
B: # This is the table of values we'll plot.

T:=plot([B[..,[1, 2]],B[1..1,[1, 2]], B[.., [3, 4]],B[1..1,[3, 4]], 
     B[..,[5, 6]],B[1..1,[5, 6]],B[.., [7, 8]],B[1..1,[7, 8]]], 
    legend = ["","BFFM","", "BNM","", "BHM","", "ARKN"],
    #title="Efficiency Curve for Example 5",
    style = ["pointline","point","pointline","point","pointline","point","pointline","point"], 
    symbolsize = 15,axes = framed, 
    symbol = [box,box, circle,circle,solidbox, solidbox,solidcircle, solidcircle],
    color=[ red, red, gold,gold, blue, blue,black, black], 
    axis = [gridlines = [colour = green, majorlines = 1,linestyle = dot]], 
    labels = [typeset(log__10(`NFE`)), typeset(log__10(`Max Err`))]);

Please I have an issue with the attached plot code. Can you kindly help to correct it? 

restart:
interface(rtablesize=infinity):
B:=<<0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.49,"0","0.05","0.1","0.15","0.2","0.25","0.3","0.35","0.4","0.45","0.49">|
	<14.73,14.4,14,13.4,12.67,11.67,10.4,8.67,6,3,0,"14.73","14.4","14","13.4","12.67","11.67","10.4","8.67","6","3","0">|
     <-0.007072,0.013309,0.033707,0.054125,0.074571,0.095056,0.115597,0.136218,0.156956,0.177867,0.199036,0.22059,0.242719,0.265702,0.289932,0.31592,0.344214,0.375124,0.408175,0.441761,0.473484,0.501857>|
	<1.34E+01,1.33E+01,1.33E+01,1.32E+01,1.31E+01,1.31E+01,1.30E+01,1.29E+01,1.28E+01,1.26E+01,1.25E+01,1.22E+01,1.19E+01,1.14E+01,1.08E+01,9.86E+00,8.58E+00,6.90E+00,4.90E+00,2.81E+00,1.00E+00,-2.86E-01>>:

B:
 
 plot([B[..,[1, 2]],B[1..1,[1, 2]], B[.., [3, 4]],B[1..1,[3, 4]], B[..,[5, 6]],B[1..1,[5, 6]],B[.., [7, 8]],B[1..1,[7, 8]],
 	  B[..,[9, 10]],B[1..1,[9, 10]], B[.., [11, 12]],B[1..1,[11, 12]],B[..,[13, 14]],B[1..1,[13, 14]],B[.., [15, 16]],B[1..1,[15, 16]],
 	  B[..,[17, 18]],B[1..1,[17, 18]], B[.., [19, 20]],B[1..1,[19, 20]],B[..,[21, 22]],B[1..1,[21, 22]]],
 	  legend = ["","Experimental","","Simulation"],
 	  style = ["line","line","line","line","line","line","line","line","line","line","line","line","line","line","line","line",
 	 		"line","line","line","line","line","line"],
 	  color=[blue,red], labels=[`V (V)`, `Jsc (mA/cm^2)`]);
 



Download Graph_Example.mw

In the following code, I want the base of the logarithm in the label to appear at the conventional position not beside the logarithm. How can I achieve this? Thank you all in anticipation of your educative response and do stay safe.

restart;

B:=<<39,76,151,301,601>|<7.71E-8,5.43E-9,3.55E-10,2.11E-11,1.32E-12>|
	<26,51,101,201,401>|<6.46E-3,1.17E-4,1.88E-6,2.96E-8,4.46E-10>|
	<26,51,101,201,401>|<2.74E-4,6.34E-6,1.16E-7,1.85E-9,2.92E-11>|
	<26,51,101,201,401>|<6.48E-4,4.39E-5,2.99E-6,1.88E-7,1.18E-8>>:

for i from 1 to 5 do
   B[i, 2] := log[10](B[i, 2]):		  			
   B[i, 4] := log[10](B[i, 4]): 		
   B[i, 6] := log[10](B[i, 6]): 		
   B[i, 8] := log[10](B[i, 8]):	
       

   
end do:  # computing the log of the max-error
B: # This is the table of values we'll plot.

T:=plot([B[..,[1, 2]],B[1..1,[1, 2]], B[.., [3, 4]],B[1..1,[3, 4]], 
	 B[..,[5, 6]],B[1..1,[5, 6]],B[.., [7, 8]],B[1..1,[7, 8]]], 
	legend = ["","BFFM","", "BHT","", "BHTRKNM", "", "BNM"],
	#title="Efficiency Curve for Example 1",
	style = ["pointline","point","pointline","point","pointline","point","pointline","point"], 
	symbolsize = 15,axes = framed, 
	symbol = [box,box, circle,circle,diamond,diamond,solidcircle, solidcircle],
	color=[red, red, blue,blue, black, black, green, green], 
	axis = [gridlines = [colour = green, majorlines = 1,linestyle = dot]], 
	labels = ["NFE", "log[10](Max Err)"]);

 

1 2 3 4 5 6 7 Page 3 of 8