# Numerical second order pde solver

• DivergentSpectrum
In summary, the conversation discusses a programming issue with a program tracking the position of a particle in a force field using a numerical method. The code provided is used to calculate the velocity and position of the particle, but it is not working as expected. Different methods, such as RK4 and one trapezoidal corrector step, are suggested to troubleshoot the issue. The importance of checking values with a calculator or debugger is also mentioned.

#### DivergentSpectrum

Edit:whoops wrong forum mods please move

2nd edit: I just had dinner then got back on the computer, input some points and saw a beautiful elipse.(complete with a fascinating flower petal design due to inaccuracies) Weird lol! No idea why it wasnt working before Now to implement RK4 bwahahaha

im writing a program in WPF(an amalgam of c# and xaml) that tracks the position of a particle after a certain amount of time.
the particle is placed in a force field, where force is a function of position and velocity.
I used a crude numerical method, which seemed pretty obvious to me but for some reason it won't work. the particle appears to travel in a straight line as if there was no force.

the number of increments and the final time to be calculated for is decided by the user, and the variable dt is calculated from that.
vx,vy,vz are the velocity vector
ax,ay,az are functions, and also the acceleration vector.

heres the relevant code. I am pretty sure the problem is in the first block.

Code:
      while (i < n - 1)
{

vx[i+1] = vx[i] + dt * ax(x[i], y[i], z[i], vx[i], vy[i], vz[i]);
vy[i + 1] = vy[i] + dt * ay(x[i], y[i], z[i], vx[i], vy[i], vz[i]);
vz[i + 1] = vz[i] + dt * az(x[i], y[i], z[i], vx[i], vy[i], vz[i]);

x[i + 1] = x[i] + vx[i + 1] * dt;
y[i + 1] = y[i] + vy[i + 1] * dt;
z[i + 1] = z[i] + vz[i + 1] * dt;

i++;
}

for verifiability, I am using a gravitational field, also for simplicity i have eliminated force from the equation and I am working with acceleration alone(ill add that later)
here i have methods define the acceleration vectors:

Code:
     //acceleration vectors x componentvvvvvvv
static double ax(double x, double y, double z, double vx, double vy, double vz)
{
double ax =  10000*(-x / Math.Pow(Math.Sqrt(x * x + y * y + z * z), 3));
return ax;
}
//acceleration vectors x component^^^^^^

//acceleration vectors y componentvvvvvvv
static double ay(double x, double y, double z, double vx, double vy, double vz)
{
double ay =  10000*(-y / Math.Pow(Math.Sqrt(x * x + y * y + z * z), 3));
return ay;
}
//acceleration vectors y component^^^^^^

//acceleration vectors z componentvvvvvvv
static double az(double x, double y, double z, double vx, double vy, double vz)
{
double az =  10000*(-z / Math.Pow(Math.Sqrt(x * x + y * y + z * z), 3));
return az;

}
//acceleration vectors z component^^^^^^

Last edited:
If you don't want to do RK4, you could try one trapezoidal corrector step:

Code:
    vx[i+1] = vx[i] + dt * ax(x[i], y[i], z[i], vx[i], vy[i], vz[i]);
/* ... */
x[i+1] =  x[i] + dt * vx[i];
/* ... */
vx[i+1] = vx[i] + .5 * dt * (ax(x[i], y[i], z[i], vx[i], vy[i], vz[i]) +
ax(x[i+1], y[i+1], z[i+1], vx[i+1], vy[i+1], vz[i+1]));
x[i+1] =  x[i] + .5 *dt * (vx[i]  + vx[i+1]);

update - see that you plan on using rk4, so no need to implement the corrector step method.

Last edited:
The best way to find the problem this would be to print out all the variables for one time step (or inspect them with your IDE's debugger, if you can believe what it's telling you!) and check the values with a calculator.

The code looks sensible, but if this is a snippet from a system that is built with tools that many people here have probably never used, the cause could be almost anything.

## What is a numerical second order pde solver?

A numerical second order pde solver is a software program that uses numerical methods to solve second order partial differential equations (PDEs). These equations involve functions of multiple variables and their partial derivatives, and are commonly used to model physical systems in fields such as physics, engineering, and finance.

## How does a numerical second order pde solver work?

A numerical second order pde solver works by discretizing the PDE into a set of algebraic equations, which can then be solved using numerical methods such as finite difference, finite element, or spectral methods. These methods approximate the solution at discrete points in space and time, and the accuracy of the solution depends on the size of the discretization.

## What types of problems can a numerical second order pde solver solve?

A numerical second order pde solver can solve a wide range of problems, including diffusion problems, wave propagation, heat transfer, fluid dynamics, and many others. It can handle both steady-state and time-dependent problems, and can also handle non-linear PDEs.

## What are the advantages of using a numerical second order pde solver?

There are several advantages to using a numerical second order pde solver. First, it allows for the solution of complex problems that may not have analytic solutions. Second, it can handle problems with irregular or complex geometries. Third, it can handle problems with variable coefficients. Finally, it can provide a fast and efficient solution compared to traditional analytical methods.

## What are the limitations of a numerical second order pde solver?

Although a numerical second order pde solver can solve a wide range of problems, it also has limitations. It is only an approximation of the true solution, so the accuracy depends on the size of the discretization. It also requires a significant amount of computational resources, especially for high-dimensional problems. Additionally, it may struggle with problems where the solution changes rapidly or has steep gradients.