# Convert differential equation to finite difference equation

• Hypatio
In summary: I still don't see where 1/3 and the r^3 are coming from. It looks like it comes out of an integration over time but the dr/dt in such an integral seems to make it go to r^4.

#### Hypatio

I have the differential equation

$\frac{dM}{dt}=4\pi \rho(r,t)r(t)^2\frac{dr}{dt}$

which is the first term from

$M(t)=4\pi\int_0^{r(t)}C(r,t)r(t)^2dr$

This describes the change in mass (M) of a sphere from a change in radius (r) given a density (rho) that depends on radius and time (t).

My problem is somewhat simple. I tried to convert this equation into a finite difference formula as follows:

$M_1-M_0=4\pi \rho(r,t)r^2(r_1-r_0)$

where subscript 1 indicates the value at a new timestep.

I must be doing something wrong because the volume of a sphere requires a 1/3 to come from somewhere on the right hand side..

Hmm..
1. Haven't you forgotten the integral term in dM/dt that sums up the rate of mass change due to the local rate of change of the density function?

arildno said:
Hmm..
1. Haven't you forgotten the integral term in dM/dt that sums up the rate of mass change due to the local rate of change of the density function?

Yes the full form is

$\frac{dM}{dt}=4\pi \rho(r,t)r(t)^2\frac{dr}{dt}+4\pi\int_0^{r(t)}\frac{\partial \rho}{\partial t}x^2 dx$

but I don't see how the 1/3 for the first term can come from the additional term. My problem with the finite-difference conversion would remain if I assumed $\rho$ did not depend on time (thus removing the last term).

Hypatio said:
Yes the full form is

$\frac{dM}{dt}=4\pi \rho(r,t)r(t)^2\frac{dr}{dt}+4\pi\int_0^{r(t)}\frac{\partial \rho}{\partial t}x^2 dx$

but I don't see how the 1/3 for the first term can come from the additional term. My problem with the finite-difference conversion would remain if I assumed $\rho$ did not depend on time (thus removing the last term).
As it should be.
Let's review the case in which the density is constant.

We then have:
$$M(t+\bigtriangleup{t})=\frac{4\pi\rho}{3}r(t+\bigtriangleup{t})^{3}\approx\frac{4\pi\rho}{3}(r(t)+\frac{dr}{dt}\bigtriangleup{t})^{3}\approx\frac{4\pi\rho}{3}r(t)^{3}+{4\pi}r(t)^{2}\frac{dr}{dt}\bigtriangleup{t}=M(t)+{4\pi}r(t)^{2}\frac{dr}{dt}\bigtriangleup{t}$$
when we discard non-linear terms in the time interval.

Last edited:
I still don't see where 1/3 and the r^3 are coming from. It looks like it comes out of an integration over time but the dr/dt in such an integral seems to make it go to r^4.

Hypatio said:
Yes the full form is

$\frac{dM}{dt}=4\pi \rho(r,t)r(t)^2\frac{dr}{dt}+4\pi\int_0^{r(t)}\frac{\partial \rho}{\partial t}x^2 dx$

but I don't see how the 1/3 for the first term can come from the additional term. My problem with the finite-difference conversion would remain if I assumed $\rho$ did not depend on time (thus removing the last term).

$$\frac{dM}{dt}=\frac{4\pi}{3} \rho(r^3,t)\frac{dr^3}{dt}+\frac{4\pi}{3}\int_0^{r^3(t)}\frac{\partial \rho}{\partial t}dx^3$$

## 1. What is the purpose of converting a differential equation to a finite difference equation?

Converting a differential equation to a finite difference equation allows us to approximate the solution to the differential equation using numerical methods. This is useful when the differential equation cannot be solved analytically or when we want to study the behavior of the solution over discrete time intervals.

## 2. How do you convert a differential equation to a finite difference equation?

The conversion process involves discretizing the independent variable (usually time) and approximating the derivatives using finite difference approximations. The resulting finite difference equation will have the same form as the original differential equation, but with finite difference terms instead of derivatives.

## 3. Are there any limitations to converting a differential equation to a finite difference equation?

Yes, there are limitations to this conversion process. The accuracy of the finite difference approximation depends on the step size of the discretization and can lead to errors. Also, some differential equations may not have a stable and accurate finite difference representation.

## 4. Can finite difference equations be solved analytically?

No, finite difference equations are solved numerically using iterative methods. These methods involve using the known initial conditions to calculate the solution at discrete time steps until a desired level of accuracy is achieved.

## 5. How is the accuracy of a finite difference solution evaluated?

The accuracy of a finite difference solution can be evaluated by comparing it to the solution of the original differential equation or by performing a convergence analysis. This involves decreasing the step size and observing how the solution changes, with a more accurate solution having a smaller change as the step size decreases.