|
"Kennedy Kwasi" wrote in message <jl4amv$2ng$1@newscl01ah.mathworks.com>...
> How do i write a matlab script to generate an 80x80 matrix to satisfy the following conditions:
> for i=1:80; for j=1:80 , if j==i , a(i,j)=2*i
> else if j=i+2, for i=1:78 or j=i-2, for i=3:80, a(i,j)=0.5*i
> else if j=i+4, for i=1:76 or j=i-2, for i=5:80, a(i,j)=0.25*i
> else a(i,j)=0
- - - - - - - - - - - -
You've committed horrible atrocities with matlab's syntax, but I'm guessing you mean this:
n = 80;
M = diag((1:n)*2)+diag((1:n-2)/2,2)+diag((3:n)/2,-2) ...
+diag((1:n-4)/4,4)+diag((5:n)/4,-4);
(I'm assuming you mean j=i-4 instead of j=i-2 in the line
"else if j=i+4, for i=1:76 or j=i-2, for i=5:80, a(i,j)=0.25*i" .)
Roger Stafford
|