Plotting with 3 variables
16 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
TED MOSBY
2024-11-13,6:11
编辑:TED MOSBY
2024-11-18,19:52
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 个评论
Walter Roberson
2024-11-13,6:31
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!