I have a vector of certain value and angle between the vector to the x axis how do i plot it in matlab ? vector value = 100 angle is 30 degrees i need that in a plane help!

6 views (last 30 days)
I have a vector of certain value and angle between the vector to the x axis how do i plot it in matlab ? vector value = 100 angle is 30 degrees i need that in a plane help!
I need it in a 2D plane and also there should be an another vecotrs from same point of the start of first vecot ..... its not values of (x,y) i have value of vector v1 = 100 and angle between x axis and vector = 30 and V2 = 200 and angle between x axis and vector = -45 degrees
How to find the resultant vector of that

Answers (1)

Hari
Hari on 3 Sep 2024
Hi Siddharth,
I understand that you want to plot two vectors in a 2D plane, given their magnitudes and angles with respect to the x-axis, and also determine the resultant vector.
I assume the angles provided are in degrees, and you want to visualize these vectors starting from the origin.
  • Convert Angles to Radians: MATLAB trigonometric functions use radians, so first convert the angles from degrees to radians.
angle1 = 30; % Angle for vector V1 in degrees
angle2 = -45; % Angle for vector V2 in degrees
rad1 = deg2rad(angle1);
rad2 = deg2rad(angle2);
  • Calculate Vector Components: Use the magnitude and angle to find the x and y components of each vector.
V1 = 100; % Magnitude of vector V1
V2 = 200; % Magnitude of vector V2
% Components for V1
V1x = V1 * cos(rad1);
V1y = V1 * sin(rad1);
% Components for V2
V2x = V2 * cos(rad2);
V2y = V2 * sin(rad2);
  • Plot the Vectors: Use the "quiver" function to plot these vectors from the origin.
figure;
hold on;
quiver(0, 0, V1x, V1y, 0, 'r', 'LineWidth', 2); % Plot V1
quiver(0, 0, V2x, V2y, 0, 'b', 'LineWidth', 2); % Plot V2
  • Calculate the Resultant Vector: Sum the components of the vectors to find the resultant vector.
Rx = V1x + V2x;
Ry = V1y + V2y;
R = sqrt(Rx^2 + Ry^2); % Magnitude of the resultant vector
R_angle = rad2deg(atan2(Ry, Rx)); % Angle of the resultant vector in degrees
  • Plot the Resultant Vector: Add the resultant vector to the plot.
quiver(0, 0, Rx, Ry, 0, 'k', 'LineWidth', 2, 'MaxHeadSize', 2); % Plot Resultant
legend('V1', 'V2', 'Resultant');
xlabel('X-axis');
ylabel('Y-axis');
axis equal;
grid on;
title('Vector Plot and Resultant');
Sample output:
References:
Hope this helps!

Community Treasure Hunt

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

Start Hunting!