How can I illustrate a sinusoidal plane wave in MATLAB?

21 views (last 30 days)
Wikipedia's article Sinusoidal plane wave - Wikipedia shows the below image:
I am able to plot the red sine wave and the the blue lines (without the arrows) but I am unable to plot the planar vector fields.
How can I replicate the above image in a MATLAB figure?

Accepted Answer

Aravind Varma Dantuluri
Aravind Varma Dantuluri on 18 Apr 2024
Thanks to Hassaan answer, I got to know about quiver function and used the below code to get the required image
mArrow3([0 0 0],[10 0 0],'color','red','stemWidth',0.05);
mArrow3([0 0 0],[0 10 0],'color','red','stemWidth',0.05);
mArrow3([0 0 0],[0 0 10],'color','red','stemWidth',0.05);
view(32, 32);
x = 0:0.1:10;
sine_wave = 5*sin(x);
hold on;plot3(x,zeros(length(x),1),sine_wave,'b');
vector_3d_x = 0:1:10;
vector_3d_y = 0:1:10;
vector_3d_z = 0:1:10;
[X,Y,Z] = meshgrid(vector_3d_x,vector_3d_y,vector_3d_z);
U = zeros(size(X));
V = zeros(size(Y));
W = sin(X);
hold on;quiver3(X, Y, Z, U, V, W, 'k');

More Answers (1)

Hassaan
Hassaan on 17 Apr 2024
Edited: Hassaan on 17 Apr 2024
% Define the domain
x = linspace(-2*pi, 2*pi, 100);
z = linspace(-2, 2, 20);
[X, Z] = meshgrid(x, z);
% Define the wave
y = sin(X);
% Create a new figure
figure;
% Plot the sinusoidal wave
surf(X, y, Z, 'FaceColor', 'red', 'EdgeColor', 'none');
alpha 0.5; % Making the surface semi-transparent
hold on;
% Plot the lines (without arrows)
for i = 1:size(Z, 1)
plot3(X(i, :), y(i, :), Z(i, :), 'b');
end
% Now let's add the planar vector fields using quiver3
[U, V, W] = deal(zeros(size(X))); % Preallocate U, V, W for quiver3
V = ones(size(X)); % Vectors point in the positive y-direction
% Create a grid in the y-direction for the vectors
Y = -2:0.5:2;
% Plot the vectors on each plane
for i = 1:length(Y)
quiver3(X, Y(i)*ones(size(X)), Z, U, V, W, 'k', 'MaxHeadSize', 0.005);
end
% Set the view angle
view(30, 45);
% Labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Sinusoidal Plane Wave with Planar Vector Fields');
% Remove the ticks
set(gca, 'XTick', [], 'YTick', [], 'ZTick', []);
% Remove the box around the plot
box off;
% Keep the axis aspect ratio normal
axis normal;
hold off;
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  1 Comment
Aravind Varma Dantuluri
Aravind Varma Dantuluri on 17 Apr 2024
Thank you for the answer
But the vector field does not vary with the amplitude of sine wave as it is being done in the image in question?

Sign in to comment.

Categories

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

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!