Plotting Temperature profile as a function of x,y and z.

조회 수: 39 (최근 30일)
Nihal Acharya
Nihal Acharya 2018년 6월 25일
댓글: Nihal Acharya 2018년 6월 28일
Hello,
I have a temperature function, which is a function of all 3 co-ordinates x,y and z. It is just one equation which iterates in for loops. But I am unable to plot this temperature function in 3D space.
I would really appreciate some help with the plotting aspect. I don't know how exactly to use isosurface or slicing even though I went through a couple of questions posted here.
Thanks in advance!
%Properties of the system
eta = 0.5;
P = 200;
v = 0.1;
k = 42.7;
d = 0.0038;
rho = 7850;
Cp = 477;
T0 = 300;
fileID = fopen('myfile.txt','w');
Q=eta*P/v;
alpha = k/Cp;
for t = 1:1:100
for x = 1:1:10
for y = 1:1:10
for z = 1:1:10
psi = x - v*t;
R = sqrt(psi^2 + y^2 + z^2);
T(:) = (Q/(2*pi*k*d))*exp(-v*psi/(2*alpha))*exp(-(v*R)/(2*alpha))/R + T0;
fprintf('%f\n', T)
fprintf(fileID,'%d\t%d\t%d\t%f\n',x,y,z,T);
end % z loop end
fprintf(fileID,'\n');
end % y loop end
fprintf(fileID,'\n');
end % x loop end
fprintf(fileID,'\n');
end % t loop end

채택된 답변

Boris Blagov
Boris Blagov 2018년 6월 25일
편집: Boris Blagov 2018년 6월 25일
I think you have many more dimensions than three - you have five dimensions. x,y,z,t and the values (temperature)
You have one T for each (x,y,z) triple and you have hundred triples for t = 1:100.
For example, you have one temperature associated with x=1, y=1 (conditional on z and t), another temperature associated with x = 2 and y = 1 (conditional on z and t) and so forth. You can generate a 3-D plot, conditioning on two of the four variables, i.e. for the temperature as a function of all "x" and all "y", conditional on one z and one t.
Here is the code for that (just for a single t!). Consider preallocating T for speed. I have changed the line T(:) from your code to T(x,y,z) and fixed t = 1.
%Properties of the system
clc
clear
eta = 0.5;
P = 200;
v = 0.1;
k = 42.7;
d = 0.0038;
rho = 7850;
Cp = 477;
T0 = 300;
fileID = fopen('myfile.txt','w');
Q=eta*P/v;
alpha = k/Cp;
% for t = 1:1:100
t = 1;
for x = 1:1:10
for y = 1:1:10
for z = 1:1:10
psi = x - v*t;
R = sqrt(psi^2 + y^2 + z^2);
T(x,y,z) = (Q/(2*pi*k*d))*exp(-v*psi/(2*alpha))*exp(-(v*R)/(2*alpha))/R + T0;
end % z loop end
end % y loop end
end % x loop end
% end % t loop end
surf(T(:,:,1))
Edit: consider using "fclose at the end" as a general good practice
  댓글 수: 6
Walter Roberson
Walter Roberson 2018년 6월 27일
isosurface() several representative T values, getting "shells" of equal temperature in 3 space.
Nihal Acharya
Nihal Acharya 2018년 6월 28일
Hi Walter, Is the use of isosurface() here something similar to the following attached post? -
https://in.mathworks.com/matlabcentral/answers/110977-3d-density-plot-multiple-isosurfaces-on-the-same-plot
Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scalar Volume Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by