| Size: 1005 Comment:  | Size: 1068 Comment:  | 
| Deletions are marked like this. | Additions are marked like this. | 
| Line 12: | Line 12: | 
| {{{!#python | {{{#!python | 
| Line 43: | Line 43: | 
| {{attachment:upstream_start.png}} {{attachment:upstrem.png}} | 
Einführung in die Grundlagen der Numerik und das Programmieren unter Unix/Linux
Iterative Verfahren zur Bestimmung von Nullstellen
Finite Differenzen Methode zur Lösung der Advektionsgleichung
   1 from pylab import *
   2 
   3 L=100 #raeumlich
   4 M=500 #zeitschritte
   5 #c=0.1  #oder unten als sinus def
   6 dx=1./L
   7 dt=1./10
   8 X=linspace(0,1,L)
   9 u=zeros((M,L))
  10 u[0,:]=exp(-500*(X-0.5)**2) #gaussfunktion
  11 #u[0,45:55]=1. #rechteck
  12 
  13 ion()
  14 figure()
  15 line,=plot(X,u[0,:])
  16 
  17 for n in range(M-1):
  18     
  19     c=0.1*cos((n*dt)/10*pi)
  20     CFL=c*dt/dx
  21     for j in range(L-1):
  22         if CFL>0:
  23             u[n+1,j]=u[n,j]-CFL*(u[n,j]-u[n,j-1])
  24         else:
  25             u[n+1,j]=u[n,j]-CFL*(u[n,j+1]-u[n,j])
  26                                  
  27     line.set_ydata(u[n+1,:])
  28     draw()
 
  
 
