Question: How to add the output to this Proc

 

Dear all;

Please see only the last lines of this procedure,

1)I ask if this procedure give an output epsilon(x0,h). Really, I need your help. Thanks.

2) Can we plot epsilon(x0,h), versus h

 

> heun := proc (x0, h)

local x, y, i, N, k, f, ode, k1, k2, x1, x2, y1, y2;

f :=(x,y)-> 1/(1+cos(y)) ;

ode := diff(y(x), x) = f(x, y);

N := round((1/2)*x0/h);

y2 := Array(0 .. N);

x2 := Array(0 .. N);

y1 := Array(0 .. 2*N);

x1 := Array(0 .. 2*N);

x2[0] := 0; y2[0] := (1/4)*Pi;

for i from 0 to N-1 do

x1[2*i+2] := (2*i+2)*h;  k1[1] := f(x1[2*i], y1[2*i]); 

k1[2] := f(x1[2*i]+h, y1[2*i]+h*k1[1]);

y1[2*i+2] := y1[2*i]+(1/2)*h*(k1[1]+k1[2]);

x2[i+1] := (2*i+2)*h;

k2[1] := f(x2[i], y2[i]);

k2[2] := f(x2[i]+2*h, y2[i]+2*h*k2[1]);

y2[i+1] := y2[i]+h*(k2[1]+k2[2])

end do;

return firstresulat = evalf([seq([x2[i], y2[i]], i = 0 .. N)]);

return secondresulat =evalf([seq([x1[2*i], y1[2*i]], i = 0 .. N)]);

epsilon:=(x0,h)->add((firsttest[i][2]-secondtest[i][2])^2 , i=1..round(x0/(2*h))+1)

end proc;

 

 

Please Wait...