From: matlab_learner on 22 Mar 2010 23:43 my code below doesn't do the trick for the gaussian elimination. The B(i) entries are growing, and the error comes from the elimination step (the first one) and that introduces an error into the result. if i use matrices i can get it but i am not allowed to use matrices. can someone tell what i am doing wrong? tnx ========================================= a = 250; N = 80; L = 400; h = L/N; for i = 1:81 x(i) = (i-1) * h; end for i = 1:11 fi(i) = 0; end for i = 11:23 fi(i) = 100 * (sin( pi * ((x(i) - 50)/60))); end for i = 23:81 fi(i) = 0; end fi_initial = fi; %confirm boundaries fi(1) = 0; fi(81) = 0; C = -(a * delta_t)/h; a = C/2; b= -1; e = -(C/2); A = a*ones(1,78); B = b*ones(1,79); E = e*ones(1,78); for time = 1:1500 d(1) = fi(2) - a*fi(1); d(79) = fi(80) - e*fi(81); for i = 2:79 d(i) = fi(i); end j=1; while j<79 %error is here!!! B(j) is getting too big, as well as d(j) B(j+1)=B(j+1) - E(j)*(A(j)/B(j)); d(j+1)=d(j+1) - d(j)*(A(j)/B(j)); j = j+1; end % now back substitution z=79; d(z) = d(z)/B(z); while z>1 %counting down since i'm at d end of d array. d(z-1) = d(z-1) - (E(z-1)*d(z))/B(z); z=z-1; end fi(1) = 0; fi(81) = 0; for i=2:80 fi(i) = d(i-1); end whos plot(x,fi) ==================== so when i plot fi against x, fi is too high (it gets to 300, but the max should be 100), n it should peak at x = 200, but it is peaking too early (as well as being too high) at x= 150. i think its the first gaussian elimination step that is high...i believe the rest of the code might b ok (not sure as there is an error already). any help is appreciated. tnx.
From: matlab_learner on 22 Mar 2010 23:46 we are supposed to use iterative methods to solve the problem, and gaussian elimination comes into play since d(i) is the rhs of Ax = d. fi is the x in Ax = d and A, B, E are the nonzero columns in the matrix A in Ax = d but using matrices is not allowed. reading numerical analysis book on gauss elimination, they suggest mutlitpling the B(i) by a constant term and then subtracting from B(i +1)...tried that but no luck. any ideas? tnx
|
Pages: 1 Prev: MATLAB's xdr support Next: Image processing-image enhancement |