Converting MATLAB Code to Python - Jacobian and Curl

preview_player
Показать описание
Here I take a function originally written in Matlab and convert it to python using the numpy, matplotlib and mpl_toolkits libraries. The function originally given to me was from a youtube commenter and the function computes the Jacobian and Curl.
Рекомендации по теме
Комментарии
Автор

Thank you for the video . I really appreciate it .

madanbhurtel
Автор

Hello
I am looking for the equivalent of : in matlab .

benbenameur
Автор

Can you please convert del2 function to python.
Or del2() function equivalent in python

aabisabbas
Автор

Can you please do video to convert matlab to python?


%% Defining the function derived above manually

clear

dx=1;
dy=1;
NX=6;
NY=6;
NZ=6;

LM=1.5;

T=zeros(NY, NX, NZ);
T(:, :, 1) = 0;
T(:, 1, :) = 0;
T(1, :, :) = 0;
cntr=0;

%% Solving the System T(i, j, k)

cntr=0;
for Iter =1:1000
cntr = cntr +1;
T_old = T;
tmp=1;
for i=2:NX-1
for j=2:NY-1
for k=2:NZ-1

DATA = [ T(i-1, j, k) T(i+1, j, k) T(i, j-1, k) T(i, j+1, k) T(i, j, k-1) T(i, j, k+1)];
T(i, j, k) = nanmean(DATA) + 10/216;
T(i, j, k) = LM*T(i, j, k) + (1-LM)*T_old(i, j, k);
if tmp==1
tmp = tmp +1;
else
Error(tmp) = 100.*(T(i, j, k)-T_old(i, j, k)./(T_old(i, j, k)));
tmp = tmp +1;
end
end
end
end
E=max(abs(Error))
%

if cntr>1&&E <0.01
break
end
end

// Plotting the temperature

for k=1:6
TT = squeeze(T(:, :, k));
TIT = 'Temperature Distribution'; XL = 't'; YL = 'y';
figure('units', 'normalized', 'Position', [0.1 0.1 0.7 0.8])
imagesc(TT)
grid on
box on
hold on
xlabel('X')
ylabel('Y')
title(TIT)
cc= colorbar;
xlabel(cc, '^\circC')
colormap(jet(16))

set(gca, 'FontSize', 20)
end

arailym_serikbay_talaskyzy
join shbcf.ru