In [10]:
from IPython.display import display, Math, Latex
from IPython.html.widgets import interact
%matplotlib inline
In [20]:
import sympy as sp
import numpy as np
def piterate(RHS, x0, y0, N):
#PicardIterations for initial value problems
#Solve y' = f(x,y(x)), y(x0) = y0 using sympy
yp = y0
for i in range(N):
yp = y0+sp.integrate(RHS.subs(y,yp), (x,x0,x))
Math(sp.latex(yp))
return yp
def testinteract(x):
print x
x = sp.symbols("x")
y = sp.symbols("y")
#Define RHS: f(x, y(x)) = ...
rhs = x-y*y #RHS of 1.order ODE
#c = piterate(RHS, 0,0, 3) #Solve nonlinear problem y'(x) = x-y*y to 3 order.
#interact(piterate, RHS = rhs, x0 = (0,1,1), y0 = (0,1,1), N = (0,10,1))
#Math(sp.latex(c))
interact(testinteract,x = (1.0,10.0,1.0))
In [ ]:
x,x_m,h,X = sp.symbols("x x_m h X")
sp.integrate(h/8*(1-X)**2, (X, -1, 1))
sp.integrate(h/8*(1+X)*(1-X), (X, -1, 1))
x = x_m + h/2*X
b_0 = sp.integrate(h/4*x*(1-x)*(1-X), (X, 0, sp.symbols("t")))
Math(sp.latex(b_0))
#Math(b_0)
In [ ]: