Plotting with 3 variables

조회 수: 2 (최근 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 CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by