Nugroho's blog.: What About Unbounded End?

Sunday, May 7, 2017

What About Unbounded End?


Yeah, what about it? The previous code have the both end bounded.

If we want a free/unbound end, we could set the condition at the with this properties (or we could choose whatever we like)

dy/dx=0

So we will have

y[1]-y[0]=0
y[0] = y[1]

if we want both free ends, we could set the other end as well

y[n] = y[n-1]

So, we just have to modify the original just a bit.

Beware though, with both ends free, we could lost the strings, :)




Here's the code
from pylab import *
import matplotlib.animation as animation

fig,ax = subplots()

def waves(y0,y1,cb):
    y2 = y0
    for i in range(1,len(y0)-1):
        y2[i] = 2*y1[i]-y0[i]+cb*(y1[i+1]-2*y1[i]+y1[i-1])
    y2[0] = y2[1]
    #y2[len(y2)-1]=y2[len(y2)-2]
    return y2

x   = linspace(0.,1.,20)
dx  = 1./(len(x))
y0  = sin(2*pi*x)
vy0 = 12.

b   = 1./32.  #dt2/dx2
dt  = sqrt(b*dx*dx)
print dt

c   = 1.

cb  = c*b

y1  = y0 + vy0*dt

print y0
print y1

line,   = ax.plot(x,y0)
def animate(i):
    global y0,y1,cb
    y2  = waves(y0,y1,cb)
    y0  = y1
    y1  = y2
    line.set_ydata(y0)
    return line,


#plot (x,y0)

ani =  animation.FuncAnimation(fig, animate, np.arange(1,200), interval =  25, blit=False)

grid(True)
ylim(-10,10)
show()


.

No comments:

323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)