Please help me to plot theta_2 and theta_4 in a graph please. I try this code but the graph shows blank
Mostra commenti meno recenti
clear all
% Create constant parameters
a = 400; b = 420; c = 450; d = 650;
% Define constant parameters
K1 = d/a
K2 = d/c
K3 = (((a^2) - (b^2) + (c^2) + (d^2)) / (2*a*c))
figure
hold on
for theta_2 = 55:60
A = cosd(theta_2) - K1 - K2*cosd(theta_2) + K3
B = -2*sind(theta_2)
C = K1 - (K2 + 1)*cosd(theta_2) + K3
theta_4 = 2*atand((-B - sqrt((B^2) - 4*A*C)) / (2*A));
plot(theta_2, theta_4)
end
Risposte (1)
When plotting a single point at a time, you will have to include a marker, to obtain the points on the figure.
clear all
% Create constant parameters
a = 400; b = 420; c = 450; d = 650;
% Define constant parameters
K1 = d/a;
K2 = d/c;
K3 = (((a^2) - (b^2) + (c^2) + (d^2)) / (2*a*c));
figure
hold on
for theta_2 = 55:60
A = cosd(theta_2) - K1 - K2*cosd(theta_2) + K3;
B = -2*sind(theta_2);
C = K1 - (K2 + 1)*cosd(theta_2) + K3;
theta_4 = 2*atand((-B - sqrt((B^2) - 4*A*C)) / (2*A));
%Red hollow circle as a marker
plot(theta_2, theta_4,'ro')
end
2 Commenti
In case you want to plot a line instead of just points, you will need all the points together.
You can vectorize your code to obtain all points together -
clear all
% Create constant parameters
a = 400; b = 420; c = 450; d = 650;
% Define constant parameters
K1 = d/a;
K2 = d/c;
K3 = (((a^2) - (b^2) + (c^2) + (d^2)) / (2*a*c));
figure
%hold on
%theta_2 as a vector
theta_2 = 55:60;
A = cosd(theta_2) - K1 - K2*cosd(theta_2) + K3;
B = -2*sind(theta_2);
C = K1 - (K2 + 1)*cosd(theta_2) + K3;
%Use element-wise operations to obtain theta_4
theta_4 = 2*atand((-B - ((B.^2) - 4.*A.*C).^(1/2))./(2.*A));
%Plot a blue line with asterik markers
plot(theta_2, theta_4,'b-*')
Bao Long Do
il 28 Lug 2023
Categorie
Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

