sokobo
Loading...
Searching...
No Matches
differential_equations.h
1#pragma once
2#include "expression.h"
3#include <vector>
4#include <functional>
5
7public:
8 // Ordinary Differential Equations
9
10 // First-order ODEs
11 static std::vector<double> eulerMethod(std::function<double(double, double)> f,
12 double x0, double y0, double h, int steps);
13 static std::vector<double> rungeKutta4(std::function<double(double, double)> f,
14 double x0, double y0, double h, int steps);
15 static std::vector<double> adamsBashforth(std::function<double(double, double)> f,
16 double x0, double y0, double h, int steps);
17
18 // Higher-order ODEs (converted to system of first-order)
19 static std::vector<std::vector<double>> systemRungeKutta4(
20 std::vector<std::function<double(double, const std::vector<double>&)>> f,
21 double x0, const std::vector<double>& y0, double h, int steps);
22
23 // Boundary value problems
24 static std::vector<double> shootingMethod(
25 std::function<double(double, double, double)> f,
26 double a, double b, double alpha, double beta, int n = 100);
27
28 // Partial Differential Equations
29
30 // Heat equation (1D)
31 static std::vector<std::vector<double>> heatEquation1D(
32 double alpha, double L, double T, int nx, int nt,
33 std::function<double(double)> initialCondition,
34 std::function<double(double)> boundaryLeft,
35 std::function<double(double)> boundaryRight);
36
37 // Wave equation (1D)
38 static std::vector<std::vector<double>> waveEquation1D(
39 double c, double L, double T, int nx, int nt,
40 std::function<double(double)> initialPosition,
41 std::function<double(double)> initialVelocity);
42
43 // Laplace equation (2D) - using finite differences
44 static std::vector<std::vector<double>> laplaceEquation2D(
45 int nx, int ny, double tolerance = 1e-6,
46 std::function<double(double, double)> boundaryCondition = nullptr);
47
48 // Symbolic solutions for special cases
49 static std::shared_ptr<Expression> solveLinearODE(const std::vector<double>& coeffs,
50 std::shared_ptr<Expression> rhs);
51 static std::shared_ptr<Expression> solveSeparableODE(std::shared_ptr<Expression> expr);
52};