How Can C++ Be Used to Solve Differential Equations?

Click For Summary

Homework Help Overview

The discussion revolves around solving a differential equation using C++. The original poster presents the equation \(\frac{dv}{dt}=t\) and expresses difficulty in programming a solution, having only recently learned C++.

Discussion Character

  • Exploratory, Conceptual clarification, Mathematical reasoning, Problem interpretation

Approaches and Questions Raised

  • Participants discuss breaking down the components of the differential equation, including the dependent and independent variables. There are mentions of integrating both sides and programming each step of the solution. Some participants question whether the task involves numerical integration or symbolic integration.

Discussion Status

There is a mix of attempts to clarify the problem and offer guidance on how to approach programming the solution. Some participants provide insights into the integration process, while others express confusion about the nature of the assignment and the assumptions made regarding the order of the differential equation.

Contextual Notes

Participants note the original poster's limited experience with C++ and the potential ambiguity in the teacher's request regarding the type of integration required.

watermint
Messages
5
Reaction score
0
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 learned C++ for about 3 months. Can you help me write a solution to the following problem in C++?
[tex]\frac{dv}{dt}=t[/tex]
Thank you
 
Last edited:
Physics news on Phys.org
Let the constant after integrating equal 0, please help me.
 
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.
 
watermint said:
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 learned C++ for about 3 months. Can you help me write a solution to the following problem in C++?
[tex]\frac{dv}{dt}=t[/tex]
The solution is:

[tex]v = \frac{ds}{dt} = \frac{1}{2}t^2 + C[/itex]<br /> <br /> [tex]s = \frac{1}{6}t^3 + Ct + D[/itex]<br /> <br /> 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)?<br /> <br /> AM[/tex][/tex]
 
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...
 
Andrew Mason said:
The solution is:

[tex]v = \frac{ds}{dt} = \frac{1}{2}t^2 + C[/itex]<br /> <br /> [tex]s = \frac{1}{6}t^3 + Ct + D[/itex]<br /> <br /> 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)?<br /> <br /> AM[/tex][/tex]
[tex][tex] <br /> Why did you assume it to be a second order DE?[/tex][/tex]
 

Similar threads

  • · Replies 32 ·
2
Replies
32
Views
3K
Replies
16
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K