中心差分法的是一种直接法,属于显示的计算方法。
对于控制方程:
直接离散为如下形式:
其中:
import math as mt#------------------------------------------# This is initial conditions, like the mass# stiffness, damping coefficient and so on.# The time step is 0.1 second.m = 0.2533; k = 10; c = 0.1592; u0 = 0; udot0 = 0;dt = 0.1;p0 = 0#------------------------------------------uacc = (p0-c*udot0-k*u0)/muminus1 = u0 - dt*udot0 - (dt*dt/2)*uacckhat = m/(dt*dt) c/(2*dt)a = k - 2*m/(dt*dt)b = m/(dt*dt) - c/(2*dt)#------------------------------------------#pForce is a sine function, its amplitude is 10.#------------------------------------------def pForce(x): if x > 0.6: return 0 return 10*mt.sin(mt.pi*x/0.6)def centralDifferenceMethod(m): c = u0; d = uminus1 p = p0 for i in range(m): p = pForce(i*dt) - a*c - b*d u = p/khat c, d = u, c print(p,u)centralDifferenceMethod(11)-33.80315216664004 -1.2938510360039823
首发于 2018-03-02