Plotting with 3 variables

3 ビュー (過去 30 日間)
Pablo Cardenas
Pablo Cardenas 2014 年 11 月 9 日
編集済み: TED MOSBY 2024 年 11 月 18 日
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 件のコメント
per isakson
per isakson 2014 年 11 月 9 日
See documentation for
surface(X,Y,Z)
Pablo Cardenas
Pablo Cardenas 2014 年 11 月 9 日
they are vectors. z= Omega, x=r1, y= r2

サインインしてコメントする。

回答 (2 件)

TED MOSBY
TED MOSBY 2024 年 11 月 13 日
編集済み: TED MOSBY 2024 年 11 月 18 日
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!

Walter Roberson
Walter Roberson 2024 年 11 月 13 日
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')

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by