# Trapezoidal Method- differential equation

Page 1 of 1

## 5 Replies - 859 Views - Last Post: 11 May 2013 - 07:48 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=320828&amp;s=9b8706d0d1aff144d5b637520f1d55e9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ShoxPhysics

Reputation: 0
• Posts: 3
• Joined: 09-May 13

# Trapezoidal Method- differential equation

Posted 11 May 2013 - 04:37 PM

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?

Is This A Good Question/Topic? 0

## Replies To: Trapezoidal Method- differential equation

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11395
• Posts: 42,939
• Joined: 27-December 08

## Re: Trapezoidal Method- differential equation

Posted 11 May 2013 - 05:26 PM

This is a numerical approximation technique. Basically, you start off with an initial y-value. So y(t) = y0. Then y1 = y0 + timeDifferential * average(y0, y1). So are you looking 0.10 time units out? 1 time unit out? Whatever your time interval is, plug that in for your timeDifferential variable.

If you are familiar with Euler's method, this is essentially that method.

### #3 ShoxPhysics

Reputation: 0
• Posts: 3
• Joined: 09-May 13

## Re: Trapezoidal Method- differential equation

Posted 11 May 2013 - 06:42 PM

could you please explain some more?

### #4 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11395
• Posts: 42,939
• Joined: 27-December 08

## Re: Trapezoidal Method- differential equation

Posted 11 May 2013 - 07:10 PM

What specific questions do you have?

### #5 ShoxPhysics

Reputation: 0
• Posts: 3
• Joined: 09-May 13

## Re: Trapezoidal Method- differential equation

Posted 11 May 2013 - 07:33 PM

I am just having trouble understanding how to start coding the trapezoidal method for differential equations because the majority of the examples I have found utilize the simpler trapezoidal method for derivatives but not how to handle it for the differential equation y'=f(t,y). I am relatively new to coding in C++, the majority of my experience is in Fortran but the assignment requires that it be coded in C++.

### #6 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11395
• Posts: 42,939
• Joined: 27-December 08

## Re: Trapezoidal Method- differential equation

Posted 11 May 2013 - 07:48 PM

You do understand that the trapezoidal method for a derivative means the solution for a differential equation, right? A differential equation is an equation with derivatives in it.

Essentially what you want to do is loop until you're happy with the value. It could be 10 iterations, 100 iterations, iterate until the difference in y(n) and y(n+1) is less than some epsilon value, etc. The formula is pretty cookbook in nature.