Spent a few hours on trying to figure out why the outputs are different, no luck. Python and Matlab are in a txt file along with their outputs.
Suggestions on what I should be looking at to resolve the issue?

댓글 수: 2

Walter Roberson
Walter Roberson 2017년 10월 24일
We do not have the data or NumPanels to test with.
Zach Dunagan
Zach Dunagan 2017년 10월 24일
편집: Zach Dunagan 2017년 10월 25일
I figured it out.

댓글을 달려면 로그인하십시오.

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 10월 24일
편집: Andrei Bobrov 2017년 10월 24일

0 개 추천

Small typo in MATLAB code in nu2
nu2 = atan2(-(xc(k)-xp(n))*sin(theta(k))+(yc(k)-yp(n))*cos(theta(n))+(xp(n+1)-xp(n))*sin(theta(n))-(yp(n+1)-yp(n))*cos(theta(n)),(xc(k)-xp(n))*cos(theta(n))+(yc(k)-yp(n))*sin(theta(n))-(xp(n+1)-xp(n))*...
cos(theta(n))-(yp(n+1)-yp(n))*sin(theta(n))); % fixed!

댓글 수: 3

Zach Dunagan
Zach Dunagan 2017년 10월 24일
I figured it out. I don't need the multiplication, '\' in Python means '...' in Matlab. The nu2 = atan2(x1, x2) similar to this line of code in my script. atan2(yp(k+1)-yp(k), xp(k+1)-xp(k)).
Stop Zach!
How?
cos(theta(n)-(yp(n+1)-yp(n))*sin(theta(n)))
or
cos(theta(n))-(yp(n+1)-yp(n))*sin(theta(n))
Zach Dunagan
Zach Dunagan 2017년 10월 24일
Oh... Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Zach Dunagan
Zach Dunagan 2017년 10월 25일
편집: Walter Roberson 2017년 10월 25일

0 개 추천

How would I insert zeros in the diagonal line of these 128 x 128 matrices?
nSource = -(sin(theta-transpose(theta)))*ups + (cos(theta-transpose(theta)))*wps;
ftSource = cos(theta-transpose(theta))*ups + sin(theta-transpose(theta))*wps;
nVortex = sin(theta-transpose(theta))*upv + cos(theta-transpose(theta))*wpv;
tVortex = cos(theta-transpose(theta))*upv + sin(theta-transpose(theta))*wpv;

댓글 수: 15

For the special case of square matrices, often the easiest way is
M - diag(diag(M))
For other matrices,
tril(M,1) + triu(M,1)
Zach Dunagan
Zach Dunagan 2017년 10월 26일
What if I wanted to insert a number, other than zero?
Just in case you have unsigned integers or the case where the existing value is so different from the new value that you have to worry about loss of precision:
Square matrix:
M(1:size(M,1)+1:end) = NewNumber;
Non-square matrix:
shorter = min(size(M,1),size(M,2));
lastidx = size(M,1)*(shorter-1)+shorter;
M(1:size(M,1)+1:lastidx) = NewNumber;
Zach Dunagan
Zach Dunagan 2017년 10월 26일
M = M = nSource = 128 x 128 ?
Is the M inside of the size() the vector that lays in the diag of nSource?
M is the array whose diagonal is to be set. For example,
nSource(1:size(nSource,1)+1:end) = NewNumber;
if nSource is square.
Zach Dunagan
Zach Dunagan 2017년 10월 26일
편집: Walter Roberson 2017년 10월 26일
Actually this seem to have worked for my situation.
ups(logical(eye(size(ups)))) = 0;
wps(logical(eye(size(wps)))) = 0.5;
Zach Dunagan
Zach Dunagan 2017년 10월 26일
편집: Walter Roberson 2017년 10월 26일
Can you please help me with the Matlab equivalent?
A=np.zeros((numPanels+1,numPanels+1))
A[:numPanels,:numPanels]=nSource
I just need the equivalent to this code.
A[:numPanels,-1]=np.sum(nVortex,axis=1)
A[:numPanels,:numPanels]=nSource
would be
A(1:end-1, 1:end-1) = nSource;
I am not certain about
A[:numPanels,-1]=np.sum(nVortex,axis=1)
but I suspect
A(1:end-1, end) = sum(nVortex, 2);
Zach Dunagan
Zach Dunagan 2017년 10월 26일
It worked! Thank you.
Zach Dunagan
Zach Dunagan 2017년 10월 26일
A[-1,:numPanels]=tSource[0,:]+tSource[-1,:]
Here is what I have.
A(end, 1:end) = tSource(1, :) + tSource(end, :);
Error:
Subscripted assignment dimension mismatch.
Error in ssPanelMethod (line 112) A(end, 1:end) = tSource(1, :) + tSource(end, :);
A(end, 1:end-1) = tSource(1, :) + tSource(end, :);
Zach Dunagan
Zach Dunagan 2017년 10월 27일
Thank you.
Zach Dunagan
Zach Dunagan 2017년 10월 28일
편집: Walter Roberson 2017년 10월 28일
I really want to understand these little operations, rather than constantly asking for help here...
Python code
normVelFoil=np.dot(nSource,x[:-1])+np.dot(nVortex,x[-1]*np.ones((num
Panels,1)))+normU
tangVelFoil=np.dot(tSource,x[:-1])+np.dot(tVortex,x[-1]*np.ones((numPanels,1)))+tangU
Matlab code
normVelFoil = dot(nSource, x(1:end, 1:end-1)) + dot(nVortex, x(1:end, 1:end-1) * ones(numPanels, 1)) + normU;
tangVelFoil = dot(tSource, x(1:end, 1:end-1)) + dot(tVortex, x(1:emd, 1:end-1) * ones(numPanels, 1)) + tangU;
tSource, tVortex are 128 x 128, while x is a 129 x 1.
Zach Dunagan
Zach Dunagan 2017년 10월 28일
편집: Walter Roberson 2017년 10월 28일
I changed dot to mtimes() or I could use .*
I compare the first dot to second dot of python and everything looks to be lining up. When I compare the normVelFoil outputs they don't line up.
Here is what I changed..
normVelFoil = mtimes(nSource, x(1:end-1, 1)) + mtimes(nVortex, x(end)*ones(numPanels, 1)) + normU;
Zach Dunagan
Zach Dunagan 2017년 10월 28일
I have come to a conclusion the outputs are the same. They are both extremely small values, practically zero.

댓글을 달려면 로그인하십시오.

ASHOK KUMAR MEENA
ASHOK KUMAR MEENA 2022년 4월 18일

0 개 추천

def Lagrange(x, y, n, xx):
sum = 0
for i in range(0, n + 1):
product = y[i]
for j in range(0, n + 1):
if (i != j):
product = product * (xx - x[j]) / (x[i] - x[j])
sum += product
return sum
def Trapezoidal(h, n, f):
sum = f[0]
for i in range (1, n):
sum = sum + 2 * f[i]
sum = sum + f[n]
ans = h * sum / 2
return ans

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

질문:

2017년 10월 24일

답변:

2022년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by