Example #1
0
def genGraph(finish, de, m):
    out = open("res/BASE_Graph{0}_M{1}_big.dat".format(BASE, m), "w")
    # for _ in range(5):
    #     out.write(" {0}".format(0))
    for e in np.arange(0, finish + de / 2, de):
        print(e)
        out.write("\n{0:.2f}".format(e))
        print("M =", m)
        a = genSol(e, m)
        # print(a)
        phi = np.linspace(0, T, 1001)
        sol = odeint(eqEllipse, [lam0[idx] for idx in range(4)],
                     phi,
                     args=(e, ),
                     rtol=1e-15)
        err = []
        mx, norm = Quaternion([-1, -1, -1, -1]), -1
        for cur in zip(phi, sol):
            l = lam(a, cur[0], e)
            # l = l * Quaternion([1/l.getNorm()**0.5, 0, 0, 0])
            diff = Quaternion(cur[1]) - l
            # print(diff)
            ndiff = diff.getNorm()**.5
            if ndiff > norm:
                mx = diff
                norm = ndiff
        for idx in range(4):
            out.write(" {0}".format(abs(mx[idx])))
        out.write(" {0:.1e}".format(Quaternion(mx).getNorm()**.5))
        print(Quaternion(mx).getNorm()**.5)
    print()
    out.close()
Example #2
0
def genError(finish, de):
    res = []
    out = open("res/BASE{0}_big.dat".format(BASE), "w")
    outL = open("res/BASE_Latex{0}_big.dat".format(BASE), "w")
    mx = None
    print("T =", T)
    out.write("T = {0}".format(T))
    # Mmin, Mmax = (2, 9)
    # for m in range (Mmin, Mmax):
    #     out.write(" {0}".format(m))
    # out.write("\n")
    # for m in range (Mmin, Mmax):
    #     outL.write(" {0}".format(m))
    # outL.write("\n")

    for e in np.arange(0, finish + de / 2, de):
        print(e)
        out.write("\n{0:.2f}".format(e))
        outL.write("\n${0:.2f}$".format(e))
        for M in range(Mmin, Mmax):
            print("M =", M)
            a = genSol(e, M)
            # print(a)
            phi = np.linspace(0, T, 1001)
            sol = odeint(eqEllipse, [lam0[idx] for idx in range(4)],
                         phi,
                         args=(e, ),
                         rtol=1e-15)
            err = []
            for cur in zip(phi, sol):
                l = lam(a, cur[0], e)
                # l = l * Quaternion([1/l.getNorm()**0.5, 0, 0, 0])
                diff = Quaternion(cur[1]) - l
                err.append(diff.getNorm()**.5)
            mx = max(err)
            print(mx)
            # out.write(" {0:.20f}".format(mx))
            out.write(" {0:.1e}".format(mx))
            latex = " & ${0:.1e}".format(mx) + "}$"
            latex = latex.replace("e-0", " \cdot 10^{-")
            outL.write(latex)
        outL.write("\\\\[0.25em]\n\\hline\n%")
        res.append(mx)
        print()
    out.close()
    outL.close()
    print(res)
Example #3
0
from math import sin, cos, pi
import numpy as np
from MathematicModels import Quaternion
from Gauss import solveLinear
from copy import deepcopy
from scipy.integrate import quad, odeint, ode
import matplotlib.pyplot as plt

EZ = 0.1
T = pi / 2
M = 8
# lam0 = Quaternion([1, 0, 0, 0])
# lam0 = Quaternion([0.8, 0, 0.6, 0])
lam0 = Quaternion([1, 2, 3, 4])
lam0 = Quaternion([-0.235019, -0.144020, 0.502258, 0.819610])  #  GLONASS
lam0 = lam0 * Quaternion([1.0 / lam0.getNorm()**0.5, 0, 0, 0])
Nb = 0.35

BASE = 0


def lamCircle(phi):
    ans = lam0
    return ans


def dlamCircle(phi):
    ans = Quaternion([0, 0, 0, 0])
    return ans

            print("K[{0}, {1}] = {2}".format(s, k, K[s][k]))

    f = [Quaternion([0, 0, 0, 0]) for _ in range(N)]
    # print("f =", f)
    print("---")
    for s in range(N):
        # res = [ quad(fvect, 0, T,args=(s, idx))[0] for idx in range(4) ]
        # print("res = ", res)
        f[s] = Quaternion(
            [quad(fvect, 0, T, args=(s, idx))[0] for idx in range(4)])
        print("f[", s, "] =", f[s])
        print("f[", s, "][0] =", f[s][0])
        #

    # lam0[0] = 9
    # print(lam0)

    assert (N == 1)

    a = K[0][0].getInv()
    print("Inv check (1, 0, 0, 0) =", a * K[0][0])

    a = f[0] * a
    print("a =", a)

    print("lam0 = ", lam0, lam0.getNorm())
    print("lam(0) = ", lam([a], 0))
    print("lam(T) = ", lam([a], T), lam([a], T).getNorm())

    print("Galerkin <<<")