[Numpy-discussion] Matlab to Numpy

Nils Wagner nwagner at mecha.uni-stuttgart.de
Mon Jan 28 00:37:02 EST 2002


Hi all,

Who can send me a program written in Numpy (+Vpython for graphics), 
that reproduces the results of the following Matlab code

x=linspace(0,1,25);
t=linspace(0,2,50);
[X,T] = meshgrid(x,t);
z=exp(-abs((X-.5)*(T-1)))+sin(X.*T);
subplot(3,2,1)
surf(X,T,z)
axis([0,1,0,2,0.4,2.1])
xlabel('x'),ylabel('t'),zlabel('z'),title('Actual surface')
[u,s,v] = svd(z);

for k =1:3
          zz=u(:,1:k)*s(1:k,1:k)*v(:,1:k)';
          subplot(3,2,k+1)
          surf(X,T,zz),axis([0,1,0,2,0.4,2.1])
          xlabel('x'),ylabel('t'),zlabel('z')
          title(['Rank',num2str(k),' approximation'])


              
Thanks in advance 

                  Nils




More information about the NumPy-Discussion mailing list