Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Differential equations

  1. May 31, 2005 #1
    Differential equation

    I have an equation that my teacher asked me to solve it using computer programming. I am stuck at how to do because I just learnt C++ for about 3 months. Can you help me write a solution to the following problem in C++?
    Thank you
    Last edited: May 31, 2005
  2. jcsd
  3. May 31, 2005 #2
    Let the constant after integrating equal 0, please help me.
  4. May 31, 2005 #3


    User Avatar
    Science Advisor
    Homework Helper

    Seems to me you should break it down by it's parts. You have a dependent variable 'v', the derivative of the dependent variable 'dv', an independent variable 't', and the derivative of t 'dt' v, dv, and t could have coefficients. In this case, the coefficient for v is 0 and the coefficients for dv and t are 1.

    You'll have to program each individual step in solving the problem. Separating the variables is no problem (multiply both sides by dt). You have to also program the integration. Both sides are simple anti-derivatives using the power law. That adds a variable for each side - the power associated with v and the power associated with t.

    Your program should integrate both sides by adding one to the power and then dividing the result by the new power.

    After separating the variables in your separable differential equation:

    [tex]v^0 dv = t^1 dt[/tex]

    After integrating both sides, your equation becomes:

    [tex]\frac{v^1}{1} = \frac{t^2}{2} + c[/tex]

    (If you're writing a program for this, it helps to write out everything that's happening, even the parts you automatically drop out when you're doing this by hand.)

    Since c is assumed to be zero, you can thankfully disregard it. Your coefficients all have values that allow you to ignore them in this example, but you could actually handle other coefficients in your program without much trouble.
  5. May 31, 2005 #4

    Andrew Mason

    User Avatar
    Science Advisor
    Homework Helper

    The solution is:

    [tex]v = \frac{ds}{dt} = \frac{1}{2}t^2 + C[/itex]

    [tex]s = \frac{1}{6}t^3 + Ct + D[/itex]

    Do you want the program to calculate s for a given t or do you want it to solve the differential equation (ie do an integration)?

  6. May 31, 2005 #5


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    This question doesn't make sense to me, unless the teacher is asking him to perform a numerical integration... you should remember how to compute an integral numerically from your Calc II course...
  7. May 31, 2005 #6
    Why did you assume it to be a second order DE?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook