ufability.blogg.se

Gauss seidel algorithm python
Gauss seidel algorithm python









gauss seidel algorithm python

write ( "initialAx.wav", 44100, Ax ) x = x0 count = 0 while ( linalg. """ #make noise of the initial approximation to b We should hear the song emerge from the initial guess wav data corresponding to AxĪs Ax gets closer to b (ie the residual gets smaller) X0 is our initial guess for the gauss seidel method (probably random static) wav files and then using Gauss-Seidel to iteratively solve a linear system:įrom TridiagonalMatrix import * from numpy import * from scipy.io import wavfile import scipy.fftpack import pylab import sys import os def musical_gauss_seidel ( A, b, x0, tol ): """īut output some sound every now and then.Ī is some matrix that lets gauss seidel workī is a vector that represents a. apply ( x ) - b count = count + 1 print count return xĪnd here's the code to handle reading/writing the. norm ( error ) > tol ): #update x in place apply ( x0 ) - b x = x0 count = 0 while ( linalg. upper * v except ( Inde圎rror ): print "Wrong sizes" return out #solve Ax=b using gauss seidelĭef gauss_seidel ( self, b, x0, tol ): error = self.

gauss seidel algorithm python

shape #matrix mulitplicationĭef apply ( self, v ): out = ndarray ( self. Here's the TridiagonalMatrix class I used:įrom numpy import * #a tridiagonal matrix classĬlass TridiagonalMatrix : #initialize with 3 numpy arraysĭef _init_ ( self, upper_in, diag_in, lower_in ): self. wav file needs an array of size 12*44100. A sparse matrix class is neccessary to avoid memory wav files into arrays is not tooīad in scipy. Third iteration: gauss_seidel_out000002.wavįourth iteration: gauss_seidel_out000003.wav Second iteration: gauss_seidel_out000001.wav Plots of the initial Ax, residual, and FFT of residual:Īfter one iteration the high notes become audible gauss_seidel_out000000.wavĪnd some structure is visible in the spectrum: High pitched notes in b become audible first while at the same timeĪudio of the initial 12 second.

gauss seidel algorithm python

Initial guess and write out Ax at each iteration we observe that the If we take b to be a song recording, some white noise as our Will approach b with the high frequency parts of Ax getting close to bįirst. Through iterations of Gauss-Seidel the vector Ax wav file can be read into anĪrray (call it b) of length 44100. This article incorporates text from the article Gauss-Seidel_method on CFD-Wiki that is under the GFDL license.One second of a 44.1kHz single channel. Gauss, Carl Friedrich (1903), Werke (in German), vol. 9, Göttingen: Köninglichen Gesellschaft der Wissenschaften."A Unified Proof for the Convergence of Jacobi and Gauss-Seidel Methods". Abhandlungen der Mathematisch-Physikalischen Klasse der Königlich Bayerischen Akademie der Wissenschaften (in German). "Über ein Verfahren, die Gleichungen, auf welche die Methode der kleinsten Quadrate führt, sowie lineäre Gleichungen überhaupt, durch successive Annäherung aufzulösen".











Gauss seidel algorithm python