Matrix Iterative Solution Using MATLAB.

5 views (last 30 days)
Pranjal Pathak
Pranjal Pathak on 29 Jan 2012
Hi,
Can anyone please help me in doing the following program: Here is the coding that I have tried:
a=-1:2/63:+1;
b=-1:2/63:+1;
[X,Y]=meshgrid(a,b);
S=sqrt(8).*(3.*X.^3+3.*X.*Y.^2-2.*X);% Given wave
Sx=sqrt(8).*(9.*X.^2+3.*Y.^2-2);% X-slope
Sy=sqrt(8).*(6.*X.*Y);% Y-slope
If i=1:64; j=1:64
g(i,j)=2;
if i=1:64; j=2:63
g(i,j)=3;
else 4;
P(i,j)=(W(i+1,j)+W(i-1,j)+W(i,j+1)+W(i,j-1))/g(i,j);
Q(i,j)=(Sy(i,j-1)-Sy(i,j)+Sx(i-1,j)-Sx(i,j));
W=zeros(64,64);
R(i,j)=P(i,j)+Q(i,j)./g(i,j); %Working formula
Up to this I have tried but not sure whether it is right or not?
Now, I have to find the solution of W using Jacobi method in MATLAB. Jacobi Method: Where initially I have to consider the P-matrix to be a zero matrix(i.e., all the W’s are zero) and calculate the values of R-matrix. Now, as the R-matrix is found, its value is assigned to P-matrix and the calculations are done to obtain the second R-matrix. In this way it is required to run the iteration for 4-times.
I will be a great help if anyone help me in doing this.
Thanking You!

Answers (1)

Walter Roberson
Walter Roberson on 29 Jan 2012
There is no way that code would run.
  • It is missing an 'end' corresponding to the single 'if' statement.
  • You have not given any code for your user-written function named 'If' (MATLAB is case sensitive so this is not 'if')
  • You have used an assignment ('=') in your 'if' test "if i=1:64", but assignments are not permitted there
  • The array "W" is use before you initialize it
  • As you have not initialized "i" (remember, "if" does not permit assignments), it would have its default value of sqrt(-1) and you would then try to index arrays with that sqrt(-1) as a subscript
I recommend that you have another look at the documentation to see the difference between "if" and "for". I also recommend that you note that you cannot "for" over two different variables in the same "for" statement.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!