Trapezoidal method differential equation

Hello,
I am working on a program to find the value of the current in a coil. This value satisfies the following equation:
y'=sin(2t)-[(ey-1)/(ey+1)]

which is of the form y'=f(t,y)

I know that in order to solve this I need to use the trapezoidal method to solve a differential equation, the formula is:
yn+1=yn+.5*h(f(tn,yn)+f(tn+1,yn+1) where h=tn+1-tn

I have found examples of the standard trapezoidal method but I do not think they will help because of the difference in the formulas. Can anybody give me some guidance here?
ShoxPhysics wrote:
I know that in order to solve this I need to use the trapezoidal method to solve a differential equation, the formula is:
yn+1=yn+.5*h(f(tn,yn)+f(tn+1,yn+1) where h=tn+1-tn


I believe it's supposed to be: (check parenthesis)

yn+1=yn+.5*h(f(tn,yn)+f(tn+1,yn+1)) where h=tn+1-tn
A good explanation of what you want is at http://www.swarthmore.edu/NatSci/echeeve1/Ref/NumericInt/RK2.html

You start with an initial condition y0 at t0, and you want to find all yn at tn=t0+n*h (you calculate y on a regular grid)

1. Create a temporary value for y1, as y1,temp=y0+h*f(t0,y0)
2. Calculate the value at t1 as y1=y0+0.5*h*(f(t0,y0)+f(t1,temp,y1,temp))

Now you have y1. Repeat the same procedure to calculate y2 and so on
Topic archived. No new replies allowed.