% Define parameters
Lx = 42; % Length of the domain (fetch)
Ly = 36; % Width of the domain (cross-fetch)
nx = 420; % Number of spatial points in x-direction
ny = 360; % Number of spatial points in y-direction
x = linspace(0, Lx, nx);
y = linspace(0, Ly, ny);
[X, Y] = meshgrid(x, y); % Create 2D grid for surface
speed_factor = 8; % Regulates the speed of the waves
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
% Initialize figure for animation
figure;
h = surf(X, Y, zeros(size(X)), 'EdgeColor', 'none'); % Initialize surface
% Change the colormap to 'cool' which gives a water-like color scheme
colormap('winter');
% Set fixed axis limits
axis([0 Lx 0 Ly -0.05 0.05]); % Adjust z-axis limits as needed
xlabel('Fetch (m)');
ylabel('Cross-fetch (m)');
zlabel('Surface Elevation (m)');
title('Surface Elevation Over Time');
% Add lighting to the plot
lightangle(-45, 30); % Adjust the angle to your preference
lighting phong; % Use Phong lighting for a smoother gradient
shading interp; % Interpolate colors across surfaces and lines
% Adjust material properties to make it look more like water
material([0.5, 0.5, 0.8, 20, 1]);
% Animation loop
for ti = t
u = zeros(size(X)); % Reset surface elevation to zero before summing waves
% Sum multiple wave components
for i = 1:length(lambda)
k = 2*pi/lambda(i); % Wavenumber
omega = speed_factor * sqrt(g*k); % Angular frequency using deep water dispersion relation, adjusted by speed factor
wave_dir = [cos(dir(i)), sin(dir(i))];
k_vec = k * wave_dir;
u = u + amplitudes(i) * exp(-zeta * (X * wave_dir(1) + Y * wave_dir(2))) ...
.* cos(k_vec(1) * X + k_vec(2) * Y - omega * ti + phi(i));
end
% Add Gaussian noise to simulate wave randomness
noise_amplitude = 0.0015; % Adjust the noise amplitude as needed
gaussian_noise = noise_amplitude * randn(size(u));
u = u + gaussian_noise;
% Update the surface plot
set(h, 'ZData', u);
title(sprintf('Time: %0.2f seconds', ti));
drawnow;
% Pause briefly to control the speed of the animation
pause(0.1);
end
Assistant
It looks like you're simulating surface waves. Is there anything specific you'd like to discuss or ask about regarding the code or the simulation?