This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class Solver { | |
| public static double Delta { get; set; } = 0.1; | |
| public static void Euler(NumericalModelWithODE model) => Euler(model, Console.Out); | |
| public static void Euler(NumericalModelWithODE model, TextWriter file) { | |
| var t = model.TimeStart; | |
| var te = model.TimeEnd; | |
| var x = model.InitialValues; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class NumericalModelWithODE { | |
| public Vector InitialValues { get; } | |
| public double TimeStart { get; set; } = 0.0; | |
| public double TimeEnd { get; set; } = 1.0; | |
| public NumericalModelWithODE(params double[] initialValues) => InitialValues = new Vector(initialValues); | |
| public abstract Vector Function(double t, Vector x); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct Vector { | |
| private double[] e; | |
| public int Length => e.Length; | |
| public Vector(int size) => e = new double[size]; | |
| public Vector(params double[] elements) => e = elements; | |
| public double this[int index] { | |
| get => e[index]; | |
| set => e[index] = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using static System.Math; | |
| namespace ODEDemo { | |
| internal static class Program { | |
| public static void Main() { | |
| const double ts = 0.0; //Time of start | |
| const double te = 2.0 * PI; //Time of end | |
| const double dt = 0.1; |
NewerOlder