How can I use MATLAB to graphically visualize a function of four variables?

I want to use MATLAB to graphically visualize a function of four variables.

 Accepted Answer

To graphically visualize a function of four variables, you can use the x-axis, y-axis, z-axis, and a series of plots (time) to represent the variables. The function value is the fifth dimension, and can then be represented by color.
As an example, consider the following temperature distribtion over time of a shrinking sphere.
% Generate mesh of shrinking sphere over time
tht = linspace(-pi, pi, 40);
phi = linspace(-pi/2, pi/2, 40);
t = linspace(0, 1, 100);
[tht phi t] = meshgrid(tht, phi, t);
r = 1 - t.^2/2;
x = r.*cos(phi).*cos(tht);
y = r.*cos(phi).*sin(tht);
z = r.*sin(phi);
%Determine temperate distribution
c = abs(asin(x-t) + acos(y+t) + asin(y+t).*acos(x-t));
% Generate animation
f = figure('DoubleBuffer', 'on');
while ishandle(f)
for n = 1:size(x, 3)
if ~ishandle(f), break,end
h = surf(x(:,:,n),y(:,:,n),z(:,:,n),c(:,:,n));
axis([-1 1 -1 1 -1 1])
title(sprintf('t = %0.3f', t(1,1,n)))
drawnow
end
end

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!