def main(y0='1,0', mu=1.0, tend=10., nt=50, savefig='None', plot=False, savetxt='None', integrator='scipy', dpi=100, kwargs='', verbose=False): assert nt > 1 y = sp.symarray('y', 2) p = sp.Symbol('p', real=True) f = [y[1], -y[0] + p*y[1]*(1 - y[0]**2)] odesys = SymbolicSys(zip(y, f), params=[p], names=True) tout = np.linspace(0, tend, nt) y0 = list(map(float, y0.split(','))) kwargs = dict(eval(kwargs) if kwargs else {}) xout, yout, info = odesys.integrate( tout, y0, [mu], integrator=integrator, **kwargs) if verbose: print(info) if savetxt != 'None': np.savetxt(stack_1d_on_left(xout, yout), savetxt) if plot: import matplotlib.pyplot as plt odesys.plot_result() plt.legend() if savefig != 'None': plt.savefig(savefig, dpi=dpi) else: plt.show()
def main(y0='1,0', mu=1.0, tend=10., nt=50, savefig='None', plot=False, savetxt='None', integrator='scipy', dpi=100, kwargs='', verbose=False): assert nt > 1 y = sp.symarray('y', 2) p = sp.Symbol('p', real=True) f = [y[1], -y[0] + p * y[1] * (1 - y[0]**2)] odesys = SymbolicSys(zip(y, f), params=[p], names=True) tout = np.linspace(0, tend, nt) y0 = list(map(float, y0.split(','))) kwargs = dict(eval(kwargs) if kwargs else {}) xout, yout, info = odesys.integrate(tout, y0, [mu], integrator=integrator, **kwargs) if verbose: print(info) if savetxt != 'None': np.savetxt(stack_1d_on_left(xout, yout), savetxt) if plot: import matplotlib.pyplot as plt odesys.plot_result() plt.legend() if savefig != 'None': plt.savefig(savefig, dpi=dpi) else: plt.show()
def numerical_solver(left, right, y0, params=[], params_value=[], tstart=0., tend=10., nt=100, plot=False, savetxt='None', savefig='None', integrator='scipy', dpi=100, kwargs='', verbose=False): ''' Пояснение: y0 - начальные значения для переменных в виде строки 'X0,X1, ..., Xn' tstart, tend, nt - начало, конец и количество шагов по времени соответственно ''' ''' Zip группирует в соответствии левую и правую часть системы x, y = 'x', 'y' f = ['x**2 - y', 'y-y**3+x'] list(zip([x,y], f)) -> [('x', 'x**2 - y'), ('y', 'y-y**3+x')] ''' odesys = SymbolicSys(zip(left, right), params=params, names=True) ''' Создаем точки по t''' tout = np.linspace(tstart, tend, nt) ''' Преобразуем начальные условия ''' y0 = list(map(float, y0.split(','))) '''kwargs пока не нужен''' kwargs = dict(eval(kwargs) if kwargs else {}) ''' Интегрируем ''' xout, yout, info = odesys.integrate(tout, y0, params_value, integrator=integrator, **kwargs) return xout, yout, info if verbose: print(info) if savetxt != 'None': # stack_1d_on_left(xout, yout) -> [[t_0, x1_0, x2_0, x3_0], ... , [t_n, x1_n, x2_n, x3_n]] np.savetxt(savetxt, stack_1d_on_left(xout, yout)) if plot: odesys.plot_result() plt.legend() plt.figure(figsize=(20, 10)) if savefig != 'None': plt.savefig(savefig, dpi=dpi) else: plt.show()
def main(m=1, g=9.81, l=1, q1=.1, q2=.2, u1=0, u2=0, tend=10., nt=200, savefig='None', plot=False, savetxt='None', integrator='scipy', dpi=100, kwargs="", verbose=False): assert nt > 1 kwargs = dict(eval(kwargs) if kwargs else {}) odesys = SymbolicSys(get_equations(m, g, l)) tout = np.linspace(0, tend, nt) y0 = [q1, q2, u1, u2] xout, yout, info = odesys.integrate( tout, y0, integrator=integrator, **kwargs) if verbose: print(info) if savetxt != 'None': np.savetxt(stack_1d_on_left(xout, yout), savetxt) if plot: import matplotlib.pyplot as plt odesys.plot_result(xout, yout) if savefig != 'None': plt.savefig(savefig, dpi=dpi) else: plt.show()
def main(m=1, g=9.81, l=1, q1=.1, q2=.2, u1=0, u2=0, tend=10., nt=200, savefig='None', plot=False, savetxt='None', integrator='scipy', dpi=100, kwargs="", verbose=False): assert nt > 1 kwargs = dict(eval(kwargs) if kwargs else {}) odesys = SymbolicSys(get_equations(m, g, l)) tout = np.linspace(0, tend, nt) y0 = [q1, q2, u1, u2] xout, yout, info = odesys.integrate(tout, y0, integrator=integrator, **kwargs) if verbose: print(info) if savetxt != 'None': np.savetxt(stack_1d_on_left(xout, yout), savetxt) if plot: import matplotlib.pyplot as plt odesys.plot_result(xout, yout) if savefig != 'None': plt.savefig(savefig, dpi=dpi) else: plt.show()