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 | Science Articles, Homework Help, Discussion**

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

# Python Python and MATLAB giving different results for same code?

Tags:

Have something to add?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**