# SECTION 3.7# Example 2# Remark: This solution is a modification of the solution to Example 1, Sect 3.6.# We will use a Maple "procdure", using the proc command, to implement the subroutine on page 138. However, for simplicity, we won't implement the subroutine on page 139 (Runge-Kutta with tolerance). f := (x,y) -> y;x0 := 0; y0 := 1.; c := 1; rk4 := proc(x0,y0,c,N,PRNTR)local h,x,y,i,k1,k2,k3,k4:h := evalf((c-x0)/N): x := x0: y := y0:for i from 1 to N dok1 := h*f(x,y):k2 := h*f(x+h/2,y+k1/2):k3 := h*f(x+h/2,y+k2/2):k4 := h*f(x+h,y+k3):x := x+h:y := y+1/6*(k1+2*(k2+k3)+k4):if (PRNTR=1) then print(x,y): end if:end do:return(x,y): end proc;# Before continuing, we check rk4 with the N=1 case:rk4(x0,y0,c,1,0);# The above are the correct values of x and y.# Next, we use a loop to change N:Numbersteps := [1,2,4]:print('N','y(1)');for k from 1 to 3 doN := Numbersteps[k]:out := rk4(x0,y0,c,N,0):y := out[2]:print(N,y);end do:# Example 4f := (x,y) -> x - y^2;x0 := 0; y0 := 1.;c := 2;Numbersteps := [1,2,4,8,16];print('h','Approximation');for k from 1 to 5 doN := Numbersteps[k]:y := rk4(x0,y0,c,N,0)[2]:print(2./N,y); end do: