필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Do you see an error?

조회 수: 4 (최근 30일)
Zach Dunagan
Zach Dunagan 2017년 12월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Zach Dunagan
Zach Dunagan 2017년 12월 25일
@Stephen Cobeldick. I was braking the code down as Per isakson suggested. Maybe my reply didn't look like I was doing this. Thanks.
Christoph F.
Christoph F. 2018년 1월 9일
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.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by