ODE Solver Documentation

Comprehensive guide for solving Ordinary Differential Equations (ODEs) using numerical methods

Introduction

This web application provides numerical solutions to boundary value problems (BVPs) for ordinary differential equations (ODEs) using two different methods:

  1. Finite Difference Method
  2. Shooting Method

The application can handle second-order ODEs of the general form:

\[ y'' = f(x, y, y') \]

with boundary conditions specified at both ends of the interval \([x_{\text{start}}, x_{\text{end}}]\).

Input Format

The ODE should be entered in the input field either in the form:

\[ y'' = \text{expression} \]

or simply as the right-hand side expression (the application will automatically add "y'' = " if not present).

Supported Mathematical Operations

  • Basic arithmetic: +, -, *, /, ^ (exponentiation)
  • Elementary functions: sin, cos, tan, exp, log, sqrt, etc.
  • Constants: pi, e

Variable Names

  • Independent variable: \(x\)
  • Dependent variable: \(y\) (use \(y'\) for first derivative, \(y''\) for second derivative)

Example Inputs:

  • y'' = -y (Simple harmonic oscillator)
  • y'' = -0.1*y' - sin(y) (Damped pendulum)
  • 2*x*y' - y + x^2 (Will be interpreted as \(y'' = 2xy' - y + x^2\))

Finite Difference Method

The finite difference method approximates derivatives using finite differences and solves the resulting system of algebraic equations.

Method Overview

For a second-order ODE:

\[ y''(x) = f(x, y, y') \]

The derivatives are approximated as:

\[ y''(x_i) \approx \frac{y_{i+1} - 2y_i + y_{i-1}}{h^2} \] \[ y'(x_i) \approx \frac{y_{i+1} - y_{i-1}}{2h} \]

where \(h\) is the step size and \(y_i = y(x_i)\).

Implementation

The method:

  1. Discretizes the interval \([a, b]\) into \(N\) points
  2. Replaces derivatives with finite difference approximations
  3. Solves the resulting system of equations (using iteration for nonlinear problems)

Parameters

  • Number of points: Determines the resolution of the solution (more points = more accurate but slower)

When to Use

This method works well for linear problems and mildly nonlinear problems. It's generally more stable than the shooting method but may require more points for accurate solutions.

Shooting Method

The shooting method converts the boundary value problem into an initial value problem and uses root-finding to satisfy the boundary conditions.

Method Overview

For a problem with boundary conditions:

\[ y(a) = \alpha, \quad y(b) = \beta \]

The method:

  1. Guesses the initial slope \(y'(a) = s\)
  2. Solves the initial value problem from \(x = a\) to \(x = b\)
  3. Compares the solution at \(x = b\) with the desired value \(\beta\)
  4. Adjusts \(s\) using a root-finding algorithm (bisection in this implementation)

Implementation

This application uses:

  • RK45 method for solving the initial value problem
  • Bisection method for root-finding

Parameters

  • Tolerance: The desired accuracy for meeting the boundary condition
  • Maximum iterations: Limits the number of attempts to find the correct initial slope

When to Use

This method is particularly useful for nonlinear problems where the finite difference method might struggle. It can be more efficient for problems where good initial guesses are available.

Example Problems

1. Simple Harmonic Oscillator

Equation:

\[ y'' + y = 0 \]

Boundary conditions:

\[ y(0) = 0, \quad y(\pi) = 0 \]

Exact solution: \(y(x) = A\sin(x)\)

2. Heat Conduction in a Rod

Equation:

\[ y'' = -10 \]

Boundary conditions:

\[ y(0) = 0, \quad y(1) = 0 \]

Exact solution: \(y(x) = -5x^2 + 5x\)

3. Nonlinear Pendulum

Equation:

\[ y'' = -\sin(y) \]

Boundary conditions:

\[ y(0) = 0, \quad y(10) = 2\pi \]

This nonlinear problem demonstrates the advantage of the shooting method.

Limitations

  • Currently supports only second-order ODEs
  • Boundary conditions must be specified at both endpoints
  • For the shooting method, the solution might not converge if:
    • The initial guess is too far from the true solution
    • The problem is particularly stiff
    • The interval is too large
  • Finite difference method may struggle with:
    • Highly nonlinear problems
    • Problems with boundary layers or rapid changes