MATLAB to Python?

MRAB python at mrabarnett.plus.com
Thu Nov 18 14:07:13 CET 2010


On 18/11/2010 12:16, MATLABdude wrote:
> On Nov 17, 10:04 am, MATLABdude<matlab.d... at mbnet.fi>  wrote:
>
> Thanks guys!
>
> I still have some problems. I made the code somewhat simpler by
> dropping off some parts of it (xx, f).
>
> Now my Python code calculates 8 different values for lambda. The
> problem is that I don't know where the minus sign comes from. Also the
> values themselves are not identical compared to the values of the
> MATLAB program.
> nonhomog.py     | nonhomog.m
> -0.774244159818 | 0.9976
> -0.823595831818 | 0.9969
> -0.774374006419 | 0.5464
> -1.0            | -54.3440
> -0.774244172803 | 0.9976
> -0.774244289666 | 0.9976
> -0.823595831818 | 0.9969
> -1.0            | 0.9674
>
> The new Python code can be found here: http://pastebin.com/c1UvtXxu

Don't use:

     from math import *
     from numpy import *
     from scipy import *

because you'll never be sure where a name comes from!

Also, check for accidental integer division. (In Python 2 integer /
integer returns integer.)



More information about the Python-list mailing list