# -*- coding: utf-8 -*-
"""
Created on Wed Nov 16 12:58:59 2016
@author: loicm
"""
import numpy as np
from numpy import linalg as ln
import pylab as P
# Imports the problem formulation from Assimulo
from assimulo.problem import Explicit_Problem
from assimulo.solvers import CVode  # Imports the solver CVode from Assimulo


def rhs(t, y):
    k = 10
    A = np.array([[0, 0, 1, 0],
                  [0, 0, 0, 1],
                  [-L(y, k), 0, 0, 0],
                  [0, -L(y, k), 0, 0]])
    b = np.array([0, 0, 0, -1])
    yd = np.dot(A, y) + b

    return yd
#def rhs(t,y):
#    A =np.array([[0, 1],[-2, -1]])
#    yd=np.dot(A, y)
#
#    return yd


def L(y, k):
    norm = ln.norm(y[0:2])
    return k * (norm - 1) / norm

y0 = np.array([1.0, 1.0, 1.0, 1.0])
t0 = 0.0

model = Explicit_Problem(rhs, y0, t0)  # Create an Assimulo problem
model.name = 'Linear Test ODE'         # Specifies the name of problem

sim = CVode(model)

tfinal = 100.0        #Specify the final time

t, y = sim.simulate(tfinal) #Use the .simulate method to simulate and provide the final time
sim.plot()

722dbff6b6c2d5bfe2eb312ae93603a5721af5d9
<mask token>


def rhs(t, y):
    k = 10
    A = np.array([[0, 0, 1, 0], [0, 0, 0, 1], [-L(y, k), 0, 0, 0], [0, -L(y,
        k), 0, 0]])
    b = np.array([0, 0, 0, -1])
    yd = np.dot(A, y) + b
    return yd


def L(y, k):
    norm = ln.norm(y[0:2])
    return k * (norm - 1) / norm


<mask token>

<mask token>


def rhs(t, y):
    k = 10
    A = np.array([[0, 0, 1, 0], [0, 0, 0, 1], [-L(y, k), 0, 0, 0], [0, -L(y,
        k), 0, 0]])
    b = np.array([0, 0, 0, -1])
    yd = np.dot(A, y) + b
    return yd


def L(y, k):
    norm = ln.norm(y[0:2])
    return k * (norm - 1) / norm


<mask token>
sim.plot()

<mask token>


def rhs(t, y):
    k = 10
    A = np.array([[0, 0, 1, 0], [0, 0, 0, 1], [-L(y, k), 0, 0, 0], [0, -L(y,
        k), 0, 0]])
    b = np.array([0, 0, 0, -1])
    yd = np.dot(A, y) + b
    return yd


def L(y, k):
    norm = ln.norm(y[0:2])
    return k * (norm - 1) / norm


y0 = np.array([1.0, 1.0, 1.0, 1.0])
t0 = 0.0
model = Explicit_Problem(rhs, y0, t0)
model.name = 'Linear Test ODE'
sim = CVode(model)
tfinal = 100.0
t, y = sim.simulate(tfinal)
sim.plot()

<mask token>
import numpy as np
from numpy import linalg as ln
import pylab as P
from assimulo.problem import Explicit_Problem
from assimulo.solvers import CVode


def rhs(t, y):
    k = 10
    A = np.array([[0, 0, 1, 0], [0, 0, 0, 1], [-L(y, k), 0, 0, 0], [0, -L(y,
        k), 0, 0]])
    b = np.array([0, 0, 0, -1])
    yd = np.dot(A, y) + b
    return yd


def L(y, k):
    norm = ln.norm(y[0:2])
    return k * (norm - 1) / norm


y0 = np.array([1.0, 1.0, 1.0, 1.0])
t0 = 0.0
model = Explicit_Problem(rhs, y0, t0)
model.name = 'Linear Test ODE'
sim = CVode(model)
tfinal = 100.0
t, y = sim.simulate(tfinal)
sim.plot()

# -*- coding: utf-8 -*-
"""
Created on Wed Nov 16 12:58:59 2016
@author: loicm
"""
import numpy as np
from numpy import linalg as ln
import pylab as P
# Imports the problem formulation from Assimulo
from assimulo.problem import Explicit_Problem
from assimulo.solvers import CVode  # Imports the solver CVode from Assimulo


def rhs(t, y):
    k = 10
    A = np.array([[0, 0, 1, 0],
                  [0, 0, 0, 1],
                  [-L(y, k), 0, 0, 0],
                  [0, -L(y, k), 0, 0]])
    b = np.array([0, 0, 0, -1])
    yd = np.dot(A, y) + b

    return yd
#def rhs(t,y):
#    A =np.array([[0, 1],[-2, -1]])
#    yd=np.dot(A, y)
#
#    return yd


def L(y, k):
    norm = ln.norm(y[0:2])
    return k * (norm - 1) / norm

y0 = np.array([1.0, 1.0, 1.0, 1.0])
t0 = 0.0

model = Explicit_Problem(rhs, y0, t0)  # Create an Assimulo problem
model.name = 'Linear Test ODE'         # Specifies the name of problem

sim = CVode(model)

tfinal = 100.0        #Specify the final time

t, y = sim.simulate(tfinal) #Use the .simulate method to simulate and provide the final time
sim.plot()
