0
$\begingroup$

In MATLAB I have the following for loop:

t=10;p=20;  
n=-5:5;
[na,nb]=meshgrid(n,n); 
dI=eye(length(n));
jj=(pi*2)*(na-nb);
F=sinc((na-nb)*t).exp(pi*t*1j*(na-nb));
cr=t*dI+p*(1-dI).*F;
i=1;
for kc=-pi:pi/20:pi
T1=(kc+2*pi*na).*(kc+2*pi*nb);
M=T1*inv(cr);
N=cr;
w=eig(M,N);
vy(:,i)=sqrt(real(w(1:t))).*(t/(2*pi));
i=i+1;
end

here is a my version in mathematica, but don't work :'(

na=[-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5

-5 -4 -3 -2 -1 0 1 2 3 4 5]

nb=Transpose[na];
dI=IdentityMatrix[Length[na]]//MatrixForm 
jj=2*Pi(na-nb)//MatrixForm
F=Sinc[(na-nb)t]Exp[i(na-nb)Pi*t]//MatrixForm 
cr=t*dI+p*(1-dI)*F;
ii=1;
For[kc=-Pi,kc<Pi,kc+=Pi/15,
T1=(kc+2*Pi*na)(kc+2*Pi*nb);
M=T1.Inverse[cr];
Nn=cr;
Nnm=M/N;
w=Eigenvalues[Nnm];
vy[[:,i]]=Sqrt(Real(w[1:t]))*(t/(2*pi));
i=i+1]

help me, please!

$\endgroup$
  • 6
    $\begingroup$ I don't think your matrix is defined in proper Mathematica syntax...and why not just us ConstantArray[Range[-5, 5], 11] to build it? Also MatrixForm is just a display wrapper. It'll mess up all your calculations so leave it off. In general I think you should just take a day and read the documentation and figure out how Mathematica works rather than try to directly transcribe your MATLAB code and make yourself miserable. $\endgroup$ – b3m2a1 Sep 13 at 20:31
  • 3
    $\begingroup$ Note also that sinc is defined differently in MATLAB. $\endgroup$ – mikado Sep 14 at 6:40
  • 1
    $\begingroup$ Maybe it is a good idea to describe what you want to do in natural language first. $\endgroup$ – Αλέξανδρος Ζεγγ Sep 14 at 8:17
  • 1
    $\begingroup$ @ΑλέξανδροςΖεγγ then use WolframAlpha Notebook?! ;) $\endgroup$ – CA Trevillian Sep 14 at 18:17
  • 1
    $\begingroup$ @CATrevillian No. I mean that a description in natural language is more friendly to those unfamiliar with other programming languages but willing to act constructively. $\endgroup$ – Αλέξανδρος Ζεγγ Sep 18 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.