abdulganiy

145 Reputation

6 Badges

9 years, 144 days

MaplePrimes Activity


These are questions asked by abdulganiy

Good day, all.

Please I want to solve the following delay differential equation:

ODE := diff(y(t), t$2) = (2*(1-y(t-1)^2))*(diff(y(t), t))-y(t)

ics := y(0) = 1, (D(y))(0) = 0

using the following codes but there is an error. Please kindly help to modify the codes.

restart;
Digits:=30:

f:=proc(n)
	2*(1-(y[n-1])^2)*delta[n]+y[n]:
end proc:

g:=proc(n)
	-4*y[n-1]*delta[n-1]+2*(1-(y[n-1])^2)*f(n)-delta[n]:
end proc:


e1:=y[n+2] = -y[n]+2*y[n+1]+(1/120)*h^2*(-3*h*g(n+2)+3*g(n)*h+16*f(n+2)+16*f(n)+88*f(n+1)):
e2:=h*delta[n] = -y[n]+y[n+1]-(1/1680)*h^2*(-128*h*g(n+1)-11*h*g(n+2)+59*g(n)*h+40*f(n+2)+520*f(n)+280*f(n+1)):
e3:=h*delta[n+1] = -y[n]+y[n+1]+(1/1680)*h^2*(-152*h*g(n+1)-10*h*g(n+2)+32*g(n)*h+37*f(n+2)+187*f(n)+616*f(n+1)):
e4:=h*delta[n+2] = -y[n]+y[n+1]+(1/1680)*h^2*(128*h*g(n+1)-101*h*g(n+2)+53*g(n)*h+744*f(n+2)+264*f(n)+1512*f(n+1)):

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

err := Vector(round(N)):
exy_lst := Vector(round(N)):
numerical_y1:=Vector(round(N)):

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

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

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


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

	par1:=x[0]=t[0],x[1]=t[1],x[2]=t[2]:
	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
		printf("%6.5f%45.30f%45.30f\n", 
		h*c,res[i],res[i+2]):
		
		numerical_y1[c] := res[i]:
		
		c:=c+1:
	end do:
	iny:=res[2]:
	ind:=res[4]:
	inx:=t[2]:
	for j from 0 to 2 do
		t[j]:=inx + j*h:
	end do:
end do:
v:=time() - st;
v/4;
printf("Maximum error is %.13g\n", max(err));
NFE=evalf((N/4*3)+1);
#get array of numerical and exact solutions for y1
numerical_array_y1 := [seq(numerical_y1[i], i = 1 .. N)]:
#exact_array_y1 := [seq(exy[i], i = 1 .. N)]:

#get array of time steps
time_t := [seq](step[i], i = 1 .. N):

#display graphs for y1
with(plots):
numerical_plot_y1 := plot(time_t, numerical_array_y1, style = [point], symbol = [asterisk],
				color = [blue,blue],symbolsize = 20, legend = ["TFIBF"]);

 Thank you, and best regards.

Dear Colleague. 

I am trying to improve the results of abs(res[i] - exy) in the following codes.

restart;
Digits := 30:

# Define the function
f := proc(n)
    -0.5*y[n] + 0.5*sin(x[n] - Pi)
end proc:

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

with(LinearAlgebra):
epsilon := 10^(-10):
inx := 0:
ind := 1:
iny := 0:
h := 0.01:
n := 0:
omega := 1:
u := omega * h:
tol := 1e-4:
N := solve(h * p = 8 * Pi, p):

err := Vector(round(N)):
exy_lst := Vector(round(N)):

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

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

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");

st := time():
for k from 1 to N / 2 do
    par1 := x[0] = t[0], x[1] = t[1], x[2] = t[2]:
    par2 := y[n] = iny, delta[n] = ind:    
    
    res := eval(<vars>, fsolve(eval({e1, e2, e3}, [par1, par2]), {vars}));

    for i from 1 to 2 do
        exy := eval(sin(c * h)):
        exz := eval(cos(c * h)):
        printf("%6.5f%17.9f%15.9f%15.9f%15.9f%13.5g%15.5g\n", h * c, res[i], res[i+1], exy, exz, abs(res[i] - exy), abs(res[i+1] - exz));
        
        err[c] := abs(evalf(res[i] - exy));
        if Norm(err) <= tol then 
            h := 0.1 * h * (c + 1) * (tol/Norm(err))^(0.2);
        else 
            break
        end if;
        exy_lst[c] := exy;
        numerical_y1[c] := res[i];
        c := c + 1;
    end do;
    iny := res[2];
    ind := res[3];
    inx := t[2];
    for j from 0 to 2 do
        t[j] := inx + j * h;
    end do;
end do:
v := time() - st;
v / 4;
printf("Maximum error is %.13g\n", max(err));
NFE = evalf((N / 4 * 3) + 1);

# Get array of numerical and exact solutions for y1
numerical_array_y1 := [seq(numerical_y1[i], i = 1 .. N)]:
exact_array_y1 := [seq(exy_lst[i], i = 1 .. N)]:

# Get array of time steps
time_t := [seq(step[i], i = 1 .. N)]:

# Display graphs for y1
with(plots):
numerical_plot_y1 := plot(time_t, numerical_array_y1, style = point, symbol = asterisk, color = blue, symbolsize = 20, legend = ["TFIBF"]);
exact_plot_y1 := plot(time_t, exact_array_y1, style = point, symbol = box, color = red, symbolsize = 20, legend = ["EXACT"]);

display({numerical_plot_y1, exact_plot_y1});
Error_plot_y1 := plot(time_t, err, style = line, symbol = box, tickmarks = [piticks, decimalticks], color = navy, labels = [`h=Pi/8`, typeset(`Absolute Errors`)]);

I am suspecting that I didnt update the new h properly (I may be wrong, though). Please kindly help modify the code to allow the values of abs(res[i] - exy) to about 10^(-11). Thank you and best regards.

Dear Colleagues,

I wish to use plot3d to the attached code but always encoutered error. However, pointplot3d runs perfectly. Please I need your assistance in this regards.

Thank you all and best regards.K2_Problem_2_two_body_kepler_e=0.mw

Good day everyone.

I am trying to write a code with variable stepsize involving tolerance. two vectors are declare for the errors. However, I don't know how to declare the two errors in comparison with the tolerance. Please kindly help. Also, any other modification to the entire code is also welcomed. Thank you all and best regards.

The code is as attached.

Variable_step_size_Falkner.mw

Dear esteem Colleagues,

Please how do I modify the following two files (though similar) to get consistent errors? I am not sure where I made the mistake.

Any modifications would be appreciated.

Thank you all for your time and mentorship. Best regard

Biratu_Mapleprimes.mw

DDE_2_Mapleprime.mw

1 2 3 4 5 6 7 Page 1 of 8