62 views (last 30 days)

Show older comments

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
on 25 Jun 2018

Edited: Boris Blagov
on 25 Jun 2018

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

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

Start Hunting!