sarra

270 Reputation

6 Badges

11 years, 131 days

MaplePrimes Activity


These are questions asked by sarra

 

I have a procedure which give an approximate solution for ode.

This our procedure

RKadaptivestepsize := proc (f, a, b, epsilon, N).

It's working ( afther some 3 mistake found by a member in Mapleprime).

Then I would like to compute the error between exact and approximate.

RKadaptivestepsize: compute the approximate solution

analyticsol: analytic solution

 

## here, I compute the error
for N from 2 by 2 to 500 do
dataerror:= N->evalf(abs(RKadaptivestepsize(f,0,1,epsilon,N)[1+N][2]-(eval(analyticsol, x = 1))));
##  sequence of data error
data[error] := [seq([N, dataerror(N)], N = 2 .. 500, 2)]:
if  data[error][k][2]<=epsilon then   
printf("%a  is the number of steps required using 3-step Runge Kutta Method to achieve an  eroor of 1e-6 .", k)
break ;
end if;   
end do;
end do;

But its gives an error.: Error, reserved word `error` unexpected

Have any one an idea.

 

Dear all;

Please I need your help to find the error in my code.

I want to solve an ode, with condition on step size.

ode := diff(y(x), x) = 2*x+y(x);
f:=(x,y)->2*x-y;

analyticsol := rhs(dsolve({ode, y(0) = 1}));
RKadaptivestepsize := proc (f, a, b, epsilon, N)
local x, y, n, h,k,z,R,p;
p:=2;
h := evalf(b-a)/N; ## we begin with this setpsize
x[0] := a; y[0] := 1; ## Initialisation
for n from 0 to N-1 do  ##loop
x[n+1] := a+(n+1)*h;  ## noeuds
k[1] := f(x[n], y[n]);
k[2] := f(x[n]+h, y[n]+h*k[1]);
k[3] := f(x[n]+h/2, y[n]+h/4*(k[1]+k[2]));
z[n+1] := z[n]+(h/2)*(k[1]+k[2]);## 2-stage runge Kutta.
y[n+1] := y[n]+(h/6)*(k[1]+k[2]+4*k[3]);
R:=abs(y[n+1]-z[n+1]); ## local erreur
hstar:=sqrt(epsilon/R)
if R=<=epsilon    then
   x[n] := x[n+1]+h;
   y[n]:=y[n+1];
   n:=n+1;

else

h:=hstar;
end if
 end do;
[seq([x[n], y[n]], n = 0 .. N)];
[seq([x[n], z[n]], n = 0 .. N)];
end proc:

epsilon:=1e-8;
RKadaptivestepsize((x,y)->2*x-y,0,1, epsilon,20)

Hi.

Please, I need a code in maple for adaptative setp size control for runge Kutta.

Thank you.

 

Hi. Thanks to help me in ths question.

 

t:=[1,2,3];

f(t[1])=[3,4];  f(t[2])=[11,12];   f(t[3])=[41,1]; 

How can plot  f  versus t

 

 

 

 

Hi.

Please help to use dsolve.

Suppose I have a Matrix A of size two. Y=[u,v].

Y'(t)=A*y(t).

How can use dsolve this problem.

Thanks

 

 

 

 

First 14 15 16 17 18 19 20 Page 16 of 21