Creating 3D Wave Motion Animation using the surf Function in MATLAB

Опубликовано: 28 Июль 2026
на канале: Mechatronic-Art
292
5

close all
clear
clc

% Wave motion parameters
A = 1; % Wave amplitude
k = 2*pi/10; % Wave number
w = 2*pi/2; % Wave frequency
phi = pi/2; % Wave phase

% Time and space
t = linspace(0, 4*pi, 100); % Time interval
x = linspace(-10, 10, 100); % Spatial interval
[X, T] = meshgrid(x, t);

% Create a 3D plot using surf
figure;
h = surf(X, T, zeros(size(X)));

% Display settings
colormap('jet'); % Colors
colorbar; % Color scale
view(45, 45); % View angle
xlabel('x'); % x-axis label
ylabel('t'); % y-axis label
zlabel('Wave'); % z-axis label
title('3D Animation of a Wave'); % Plot title

% Create motion and animation
for i = 1:numel(t)
Z = A * sin(k*X - w*t(i) + phi); % Compute wave at each point and time
set(h, 'ZData', Z); % Update plot data
drawnow; % Display updated plot
pause(0.1); % Pause to create delay in animation
end