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

In summary: Differential equationI 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]s = -t^2[/tex]Thank you, but I don't understand what you're asking. In summary, the problem is asking for the value of s when t equals 2.
  • #1
watermint
5
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
  • #2
Let the constant after integrating equal 0, please help me.
 
  • #3
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.
 
  • #4
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]

[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)?

AM
 
  • #5
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...
 
  • #6
Andrew Mason said:
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)?

AM

Why did you assume it to be a second order DE?
 

1. What is a differential equation?

A differential equation is a mathematical equation that describes the relationship between a function and its derivatives. It involves both the dependent variable and its derivatives with respect to one or more independent variables.

2. What are the applications of differential equations?

Differential equations have a wide range of applications in various fields including physics, engineering, economics, biology, and chemistry. They are used to model and analyze systems that change over time, such as population growth, motion of objects, and chemical reactions.

3. How are differential equations solved?

There are various methods for solving differential equations, including separation of variables, power series, and numerical methods. The method used depends on the type and complexity of the differential equation.

4. What is the difference between ordinary and partial differential equations?

Ordinary differential equations involve a single independent variable, while partial differential equations involve multiple independent variables. Ordinary differential equations have only ordinary derivatives, while partial differential equations can have both ordinary and partial derivatives.

5. What is the importance of differential equations in science?

Differential equations are important in science because they provide a powerful tool for understanding and predicting the behavior of complex systems. They allow scientists to create models and make predictions about real-world phenomena, which can then be tested and refined through experimentation.

Similar threads

  • Introductory Physics Homework Help
Replies
16
Views
1K
  • Introductory Physics Homework Help
Replies
12
Views
409
  • Introductory Physics Homework Help
Replies
8
Views
1K
  • Introductory Physics Homework Help
Replies
2
Views
995
  • Introductory Physics Homework Help
Replies
4
Views
839
  • Introductory Physics Homework Help
Replies
2
Views
1K
  • Introductory Physics Homework Help
Replies
17
Views
376
  • Introductory Physics Homework Help
Replies
5
Views
2K
  • Introductory Physics Homework Help
Replies
10
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
867
Back
Top