I am trying to learn Python by translating my MATLAB codes into Python. My translated Python code is giving slightly different result as compared to that of MATLAB. Although difference is very small but it affects largely the results at later stage.(adsbygoogle = window.adsbygoogle || []).push({});

My Python code is

and my MATLAB code isCode (Python):import numpy as np

import math

import matplotlib.pyplot as plt

xsize=1000000

ysize=1500000

xnum=36

ynum=36

xstp=xsize/(xnum-1)

ystp=ysize/(ynum-1)

x=np.linspace(0,xsize,xnum)

y=np.linspace(0,ysize,ynum)

vx0=1e-9 * xsize/(2*ysize)

vy0=1e-9

vx=np.zeros((xnum,ynum))

vy=np.zeros((xnum,ynum))

dvxdx=np.zeros((xnum,ynum))

dvydy=np.zeros((xnum,ynum))

divv=np.zeros((xnum,ynum))

for i in range(ynum):

for j in range(xnum):

vx[i,j]=-vx0 * math.sin(math.pi*x[j]/xsize*2 * math.cos(math.pi*y[i])/ysize)

Code (Matlab M):

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Python and MATLAB giving different results for same code?

Tags:

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads - Python MATLAB giving | Date |
---|---|

Python How can I run Python by getting values from Matlab | Mar 7, 2018 |

Help: Convert Matlab to Python code | Dec 8, 2017 |

Python Matlab and Python | Mar 9, 2016 |

Python equivalent of MATLAB textscan? | Oct 23, 2012 |

Compile Python, Matlab and Python | Mar 13, 2009 |

**Physics Forums - The Fusion of Science and Community**