Converting Python to Matlab
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 24 Okt. 2017
We do not have the data or NumPanels to test with.
Zach Dunagan
am 24 Okt. 2017
Bearbeitet: Zach Dunagan
am 25 Okt. 2017
Akzeptierte Antwort
Weitere Antworten (2)
Zach Dunagan
am 25 Okt. 2017
Bearbeitet: Walter Roberson
am 25 Okt. 2017
15 Kommentare
Walter Roberson
am 25 Okt. 2017
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
am 26 Okt. 2017
Walter Roberson
am 26 Okt. 2017
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
am 26 Okt. 2017
Walter Roberson
am 26 Okt. 2017
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
am 26 Okt. 2017
Bearbeitet: Walter Roberson
am 26 Okt. 2017
Zach Dunagan
am 26 Okt. 2017
Bearbeitet: Walter Roberson
am 26 Okt. 2017
Walter Roberson
am 26 Okt. 2017
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
am 26 Okt. 2017
Zach Dunagan
am 26 Okt. 2017
Andrei Bobrov
am 26 Okt. 2017
A(end, 1:end-1) = tSource(1, :) + tSource(end, :);
Zach Dunagan
am 27 Okt. 2017
Zach Dunagan
am 28 Okt. 2017
Bearbeitet: Walter Roberson
am 28 Okt. 2017
Zach Dunagan
am 28 Okt. 2017
Bearbeitet: Walter Roberson
am 28 Okt. 2017
Zach Dunagan
am 28 Okt. 2017
ASHOK KUMAR MEENA
am 18 Apr. 2022
0 Stimmen
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
Kategorien
Mehr zu Call Python from MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!