chelchax

10 Reputation

One Badge

4 years, 123 days

MaplePrimes Activity


These are replies submitted by chelchax

@acer i was able to get the code to run, the answers are showing 0.000001 off which is weird but that's ok. It must be something else I'm doing wrong but I'll ask a peer about that. Thank you

@acer sorry didn't know that. I assumed no one would reply since an answer was given already here so I thought I had to repost it with more information.

Here is my code attached 
 

euler1 := proc (f, a, b, alpha, h, N) local i, t, w; i := 1; t := a; w := alpha; while i <= N do w := w+h*f(t, w); t := a+i*h; i := i+1 end do; [w] end proc

proc (f, a, b, alpha, h, N) local i, t, w; i := 1; t := a; w := alpha; while i <= N do w := w+h*f(t, w); t := a+i*h; i := i+1 end do; [w] end proc

(1)

euler1(e^(5*3-y), 0, 3, .5, .2, 2)

[.5+.2*e(0, .5)^(15-y(0, .5))+.2*e(.2, .5+.2*e(0, .5)^(15-y(0, .5)))^(15-y(.2, .5+.2*e(0, .5)^(15-y(0, .5))))]

(2)

NULL

NULL

NULL


 

Download p5one.mw
 

RK4 := proc (f, a, b, alpha, h, N) local t, w, i, k1, k2, k3, k4; i := 1; t := a; w := alpha; while i <= N do k1 := h*f(t, w); k2 := h*f(t+(1/2)*h, w+(1/2)*k1); k3 := h*f(t+(1/2)*h, w+(1/2)*k2); k4 := h*f(t+h, w+k3); w := w+(1/6)*k1+(1/3)*k2+(1/3)*k3+(1/6)*k4; t := a+i*h; i := i+1 end do; [w] end proc

proc (f, a, b, alpha, h, N) local t, w, i, k1, k2, k3, k4; i := 1; t := a; w := alpha; while i <= N do k1 := h*f(t, w); k2 := h*f(t+(1/2)*h, w+(1/2)*k1); k3 := h*f(t+(1/2)*h, w+(1/2)*k2); k4 := h*f(t+h, w+k3); w := w+(1/6)*k1+(1/3)*k2+(1/3)*k3+(1/6)*k4; t := a+i*h; i := i+1 end do; [w] end proc

(1)

RK4(exp(5*3-y), 0, 3, .5, .2, 1)

[.5+0.3333333333e-1*(exp(15-y))(0, .5)+0.6666666667e-1*(exp(15-y))(.1000000000, .5+.1000000000*(exp(15-y))(0, .5))+0.6666666667e-1*(exp(15-y))(.1000000000, .5+.1000000000*(exp(15-y))(.1000000000, .5+.1000000000*(exp(15-y))(0, .5)))+0.3333333333e-1*(exp(15-y))(.2, .5+.2*(exp(15-y))(.1000000000, .5+.1000000000*(exp(15-y))(.1000000000, .5+.1000000000*(exp(15-y))(0, .5))))]

(2)

``


 

Download rk4new.mw

 

Oh I see, that definitely makes sense. Wow I wasn't expecting for there to be so many errors. So is there a way my code is close to following this method? I'm following these procedures through a book. I realize the books way is not very optimal but I was looking to at least code it correctly since it looked simple enough. 

Not sure if this is important but i had to take out

h:=(b-a)/N;

because it was interferring with my h value in 

proc(f,a,b,alpha,h,N);

that im changing from 0.2,0.02,0.002. so if taking that out was a mistake, please let me know.

Page 1 of 1