Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Do you see an error?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Do any of you see a problem with the Matlab code? The output from Python and Matlab are the same except 'wps'.
The outputs for wps is attached as an image. When I was testing the primary script, I thought maybe the function files are outputting different numbers which is seen in the image. I made up several inputs in terms of arrays for both Python and Matlab.
xc = 1:5;
yc = 1:5;
xp = 1:5;
yp = 1:5;
theta = 1:5;
ups = zeros(length(xc), length(xp) - 1);
wps = zeros(length(xc), length(xp) - 1);
for i = 1:length(xc)
for j = 1:(length(xp) - 1)
r1 = ((xc(i) - xp(j)).^2 + (yc(i) - yp(j)).^2).^(1/2);
r2 = ((xc(i) - xp(j+1)).^2 + (yc(i) - yp(j+1)).^2).^(1/2);
nu2 = atan2(-(xc(i) - xp(j)) * sin(theta(j)) + (yc(i) - yp(j)) * cos(theta(j))+(xp(j+1) - xp(j)) * sin(theta(j))-(yp(j+1) - yp(j)) * cos(theta(j)),...
(xc(i) - xp(j)) * cos(theta(j)) + (yc(i) - yp(j)) * sin(theta(j)) - (xp(j + 1) - xp(j)) * cos(theta(j)) - (yp(j + 1) - yp(j)) * sin(theta(j)));
nu1 = atan2(-(xc(i) - xp(j)) * sin(theta(j)) + (yc(i) - yp(j)) * cos(theta(j)), (xc(i) - xp(j)) * cos(theta(j)) + (yc(i) - yp(j)) * sin(theta(j)));
%
ups(i, j) = 1 / (4 * pi) * log(r1.^2 / r2.^2);
wps(i, j) = 1 / (2 * pi) * (nu2 - nu1);
end
end
Here is the Python
import numpy as np
xc = np.array([1,2,3,4,5])
yc = np.array([1,2,3,4,5])
xp = np.array([1,2,3,4,5])
yp = np.array([1,2,3,4,5])
theta = np.array([1,2,3,4,5])
ups=np.zeros((len(xc),len(xp)-1))
wps=np.zeros((len(xc),len(xp)-1))
for i in range(len(xc)):
for j in range(len(xp)-1):
r1=((xc[i]-xp[j])**2+(yc[i]-yp[j])**2)**(1/2)
r2=((xc[i]-xp[j+1])**2+(yc[i]-yp[j+1])**2)**(1/2)
nu2=np.arctan2(-(xc[i]-xp[j])*np.sin(theta[j])+(yc[i]-yp[j])*np.cos(theta[j])+(xp[j+1]-xp[j])*np.sin(theta[j])-(yp[j+1]-yp[j])*np.cos(theta[j]),\
(xc[i]-xp[j])*np.cos(theta[j])+(yc[i]-yp[j])*np.sin(theta[j])-(xp[j+1]-xp[j])*np.cos(theta[j])-(yp[j+1]-yp[j])*np.sin(theta[j]))
nu1=np.arctan2(-(xc[i]-xp[j])*np.sin(theta[j])+(yc[i]-yp[j])*np.cos(theta[j]),(xc[i]-xp[j])*np.cos(theta[j])+(yc[i]-yp[j])*np.sin(theta[j]))
ups[i,j]=1/(4*np.pi)*np.log(r1**2/r2**2)
wps[i,j]=1/(2*np.pi)*(nu2-nu1)
9 Commenti
Christoph F.
il 9 Gen 2018
What are the commas doing in the nu2 and nu1 expressions? I would assume that Python and Matlab have slightly different ideas of the function of a comma operator.
Risposte (0)
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!