'ODE of Second order in python
import sympy as sym
sym.init_printing()
import scipy as sp
import matplotlib as mpl
import matplotlib.pyplot as plt
#%%
x = sym.symbols('x')
f, g = sym.symbols('f g', cls=sym.int)
# f''+ 30000*f'+ 100000000*f = 0.001
# f(0) = 0 e f'(0) = 0
diffeq = sym.Eq(f(x).diff(x, x) + (30000)*f(x).diff(x) + (100000000)*f(x), sym.(0.001))
soln = sym.dsolve(diffeq,f(x))
constants = sym.solve([soln.rhs.subs(x,0) - 0, soln.rhs.diff(x,1).subs(x,0)- 0])
C1, C2 = sym.symbols('C1,C2')
soln = soln.subs(constants)
func = sym.lambdify(x,soln.rhs,'numpy')
#%%
#ploting the solution f(x)
xx = sp.arange(-1,1,.01)
y = func(xx)
plt.figure(1)
plt.plot(xx,y);
Hi! I want to solve this ODE of second order in python but it seems I'm doing something wrong. f'' means the second derivate of f(x) f' means the first derivate of f(x)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|