MATLAB to Python?

Carl Banks pavlovevidence at
Wed Nov 17 09:46:47 CET 2010

On Nov 17, 12:04 am, MATLABdude <matlab.d... at> wrote:
> Hi!
> Can you, please, try to help me with Python? I try to convert a MATLAB
> program to Python.
> Here are the MATLAB codes:
> Here is my Python code:
> What is wrong with my Python code? The program doesn't produce quite
> the same lambdas as the MATLAB program does. My code probably has lots
> of errors because I'm just learning the basics about Python.
> Thanks for all the help!

I was about to say it was a pretty good looking piece of code, and
probably if anything is wrong it's a typo somewhere.

But then my eye caught something at the last minute:

xx = range(-kappa, h, kappa+1)

Looks like you're treating range arguments as (start,step,stop), same
order as in Matlab.  In Python it's (start,stop,step), so you should
be using this:

xx = range(-kappa,kappa+1,h)

Other than that, you might jus have to pepper your scripts with prints
and disps to catch the exact point where the discrepancy occurs.

Carl Banks

More information about the Python-list mailing list