This file contains 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
-- Lua & TI-Nspire による常微分方程式の数値解法 / ナイストレム法 | |
Nystroem = class() | |
function Nystroem:init(funcs, t0, inits, initsDot, h, numOfDiv) | |
self.Unpack = unpack or table.unpack | |
self.funcs = funcs | |
self.t0 = t0 | |
self.inits = inits | |
self.initsDot = initsDot |
This file contains 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
-- Lua による常微分方程式の数値解法 / 4 段のカウエル法 | |
function cowell4(funcs, t0, inits, h) | |
local unpack = unpack or table.unpack | |
local t0 = t0 | |
local inits = inits | |
local function maxOfErr(listA, listB) | |
local sute = {} | |
for i = 1, #listA do |
This file contains 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
-- Lua による常微分方程式の数値解法 / 補外法 | |
Extrapo = class() | |
function Extrapo:init(funcs, t0, inits, h, numOfDiv) | |
local unpack = unpack or table.unpack | |
self.numOfDiv = numOfDiv or 1 | |
self.funcs = funcs | |
self.step = h |
This file contains 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
# Python による常微分方程式の数値解法 / 補外法 | |
class Extrapo: | |
def __init__(self, funcs, t0, inits, h, numOfDiv=1): | |
self.funcs = funcs | |
self.t0 = t0 | |
self.inits = inits | |
self.h = h / numOfDiv | |
self.numOfDiv = numOfDiv | |
def __midPoints(self, funcs, t0, inits, H, S=7): |
This file contains 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
# Python による常微分方程式の数値解法 / Shanks による 12 段 8 次の Runge-Kutta 法 | |
class Shanks8: | |
def __init__(self, funcs, t0, inits, h, numOfDiv=1): | |
self.funcs = funcs | |
self.t0 = t0 | |
self.inits = inits | |
self.dim = len(funcs) | |
self.numOfDiv = numOfDiv | |
self.h = h / self.numOfDiv | |
self.f = [[None for i in range(self.dim)] for i in range(12)] |
This file contains 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
import scipy as sp | |
from scipy.integrate import odeint | |
class spODE: | |
def __init__(self, funcs, t0, inits, h=1/2**5, numOfDiv=1): | |
self.funcs = lambda v, t: [func(t, *v) for func in funcs] | |
self.t0 = t0 | |
self.inits = inits | |
self.numOfDiv = numOfDiv | |
self.h = h |
This file contains 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
# 参考: 『インターフェース』 CQ 出版, 2017 年 9 月号, p.109-111, 三上直樹 | |
# ある函数 f(x) が下のような N 次の多項式 g(x) で表現できると假定し、そこそこ精度のある近似式を求める。 | |
# f(x) ≈ g(x) | |
# g(x) ≈ c[0] * T[0] + c[1] * T[1] + ... + c[N] * T[N] | |
# T[N] はチェビシェフ多項式である。 | |
# ここでは例として f(x) = Sin(Pi * x / 2) の近似式を具体的に計算してみる。区間は -1 ≦ x ≦ 1 とする。 | |
# 区間が a ≦ x ≦ b である場合は次式 u(a, b) で変数を変換する。 | |
# u = lambda a, b: (2 * x - (b + a)) / (b - a) | |
import sympy as sym | |
import numpy as np |
This file contains 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
#include <stdio.h> | |
double contain(double var){ | |
double a; | |
double min = 0 ; | |
double max = 2.375; | |
a = (min < var)? var : min; | |
a = (a < max)? a : max; | |
return a; | |
} |
This file contains 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
# 参考: 三上直樹, (2017), 「知っ得! 軽量sin/cos計算アルゴリズム 第3回 軽量ミニマックス近似式の求め方」, 『Interface(インターフェース)』(CQ出版) 2017年 09 月号, pp.109-111 | |
from matplotlib import pyplot as plt | |
from scipy.signal import argrelmax | |
import sympy as sym | |
import numpy as np | |
import scipy as sci | |
class MinMax: |
This file contains 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
from scipy.signal import argrelmax | |
import numpy as np | |
def epsilon(f, coeffList): | |
a, b = -1, 1 # 区間 | |
dim = len(coeffList) | |
f = f | |
g = lambda x : sum([coeffList[n] * x**n for n in np.arange(dim)]) | |
ε = lambda f, g : f - g |