Vectorize nested for loops

1 Ansicht (letzte 30 Tage)
Jesus Octavio
Jesus Octavio am 18 Okt. 2020
Kommentiert: Jesus Octavio am 18 Okt. 2020
Hello everyone.
I'd like to vectorize this code:
for i = 1:N-2
for j = 1:N
Jacobian(i,j) = D2Mat(i+1,j)+(2/XCheb(i+1))*...
D1Mat(i+1,j)+(xi^2)*n*Y(i+1)^(n-1)*D0Mat(i+1,j);
end
end
where D2Mat is (NxN), XCheb is (N,1), D1Mat is (NxN), D0Mat is (NxN), Y is (N,1) and xi, n are real values.
Thanks

Akzeptierte Antwort

David Hill
David Hill am 18 Okt. 2020
Bearbeitet: David Hill am 18 Okt. 2020
Jacobian=D2Mat(2:end-1,:)+(2./XCheb(2:end-1)).*D1Mat(2:end-1,:)+((xi^2)*n*Y(2:end-1).^(n-1)).*D0Mat(2:end-1,:);
  1 Kommentar
Jesus Octavio
Jesus Octavio am 18 Okt. 2020
Thank you !!!
It was so easy... 🤦‍♂️

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by