Plotting with 3 variables
2 views (last 30 days)
Show older comments
Hi! I'm trying to Create a displacement diagram showing x versus y and z versus y if 2.5≦y≦3.5 with an increment of 0.1.
The derived equation is: 2sin(z)+x*cos(z)= -y
Note that z, x, and y are just arbitrary variables
The problem I have is that the only changing variable is y.
I am a little stuck here, please help.
3 Comments
Answers (2)
TED MOSBY
on 13 Nov 2024
Edited: TED MOSBY
on 18 Nov 2024
To create a displacement diagram with the given equation 2(sin(z)) + x(cos(z) = -y), we'll need to express (x) and (z) in terms of (y), given the range (2.5 <= y <= 3.5) with an increment of 0.1. Since (x) and (z) are arbitrary, we can choose different values for them to illustrate the displacement diagram.
% Constants
x = 1; % Arbitrary constant value for x
z = pi / 4; % 45 degrees in radians
% Range for y
y_values = 2.5:0.1:3.5;
% Initialize arrays to store x and z values
x_values = zeros(size(y_values));
z_values = zeros(size(y_values));
% Calculate corresponding x and z values
for i = 1:length(y_values)
y = y_values(i);
% Calculate x based on the equation
x_values(i) = - (2 * sin(z) + y) / cos(z);
% z remains constant in this example
z_values(i) = z;
end
% Plot x vs y
figure;
subplot(1, 2, 1);
plot(y_values, x_values, '-o');
title('x vs y');
xlabel('y');
ylabel('x');
% Plot z vs y
subplot(1, 2, 2);
plot(y_values, z_values, '-o');
title('z vs y');
xlabel('y');
ylabel('z');
% Adjust layout
set(gcf, 'Position', [100, 100, 1000, 400]);
Similarly, you can keep x as constant and calculate z accordingly.
Hope this helps!
0 Comments
Walter Roberson
on 13 Nov 2024
x = linspace(-10,10);
z = linspace(-10,10);
y = -(2.*sin(z)+x.*cos(z));
plot3(x, y, z)
xlabel('x'); ylabel('y'); zlabel('z')
0 Comments
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!