Skip to content

Instantly share code, notes, and snippets.

@Rafka86
Rafka86 / Solver.cs
Last active August 16, 2018 07:26
数値計算クラス
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;
@Rafka86
Rafka86 / NumericalModelWithODE.cs
Last active August 16, 2018 07:25
数理モデルクラス(常微分方程式)
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);
}
@Rafka86
Rafka86 / Vector.cs
Last active July 16, 2018 17:20
シリーズで使用するプログラムに使用するVector構造体
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;
@Rafka86
Rafka86 / Program.cs
Last active March 14, 2018 15:52
DemoODE
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;