Prev: how to vectorize this in matlab
Next: how to apply line folding automatially when labeling figure
From: matlab_learner on 18 Mar 2010 21:30 I have to seek help after running out of resources on this. I have a 39X39 tridiagonal matrix. We are not allowed to use Matrix operations in matlab. we r using iterative methods to solve this. We need to do gaussian elimintation on the system to solve it. It is also called a PADE scheme. We defined 3 vectors (a,b,c) for the matrix, each representing a column in the matrix, and d vector for the rhs. I found that for gauss elimination, the b entries (or B vector, which is B=b*(1:39)) are overwritten and also the d (rhs) is overwritten. However,my code doesn't seem to do justice to the results as the results are way off what they should. So here is the formula, and here is what I did. Can you pls point whats wrong in the code? tnx. the top row in the tri-diagonal matrix are just (B(0) C(0) 0 0 0 0 0.... 0), and the second row is (A(1) B(1) C(1) 0 0 0 0 0... 0) the 3rd row is (0 A(2) B(2) C(2) 0 0 0 0 0 0...0), ust like that till we get to the 39th row in the matrix (0.....A(39) B(39) ) so for gauss elimination: B(1) = B(1) - [C(0) * {A(1) / B(0) } ] .. .. B(39) = B(39) - [C(38) * {A(39) / B(38) } ] u do the same for the d(rhs) vector so d(1) = d(1) - d(0)*{A(1) / B(0)} .. .. d(39) = d(39) - d(38) * { A(39) / B(38) } that is the given formula. so given a = 12.5, b = 1, c = -12.5, i make my A B C vector (A = 12.5*ones(1,39) ), etc I did: while i<39 B(i)=B(i) - C(i-1)*A(i)/B(i-1); % d(i)=d(i) - d(i-1)*(A(i)/B(i-1)) i = i+1; end i = 2; while i<39 % B(i)=B(i) - C(i-1)*(A(i)/B(i-1)); d(i)=d(i) - d(i-1)*(A(i)/B(i-1)); i = i+1; end but the results are off...any ideas what i am doing wrong? tnx
|
Pages: 1 Prev: how to vectorize this in matlab Next: how to apply line folding automatially when labeling figure |