Effacer les filtres
Effacer les filtres

help i dont know why my code isnt working

1 vue (au cours des 30 derniers jours)
jack
jack le 25 Fév 2023
Commenté : Walter Roberson le 26 Fév 2023
a = 0; % lower bound of interval
b = 2*π; % upper bound of interval
tol = 0.001; % tolerance
while (b-a) > tol
c = (a + b) / 2; % midpoint of interval
if dy(a)*dy(c) < 0
b = c;
else
a = c;
end
min_angle = (a + b) / 2; % angle of crank for minimum y-coordinate
max_angle = (a + b) / 2 + π; % angle of crank for maximum y-coordinate
min_angle = (a + b) / 2;
% angle of crank for minimum y-coordinate max_angle = (a + b) / 2 + pi;
% angle of crank for maximum y-coordinate
% Initialize arrays to store angles and y-coordinates angles = a:0.001:b;
y_coords = zeros(size(angles));
% Calculate y-coordinate
for each angle for i = 1:length(angles) theta = angles(i);
beta = asin((CD/BC)sin(theta));
phi = pi - beta;
psi = acos((DE^2 - BC^2 - CE^2)/(2BCCE));
alpha = phi - psi;
y_coords(i) = OAcos(theta) + sqrt(OB^2 - OA^2sin(theta)^2) + CDcos(alpha) - DE*cos(beta+alpha) - d;
end
% Find the minimum and maximum y-coordinates and their corresponding angles
[min_y, min_idx] = min(y_coords);
[max_y, max_idx] = max(y_coords);
min_angle = angles(min_idx); max_angle = angles(max_idx);
% Display the results
fprintf('Minimum y-coordinate: %f at angle %f\n', min_y, min_angle);
fprintf('Maximum y-coordinate: %f at angle %f\n', max_y, max_angle);

Réponses (1)

Walter Roberson
Walter Roberson le 26 Fév 2023
b = 2*π; % upper bound of interval
π is a permitted character in MATLAB only in
  • comments
  • character vectors
  • string objects
Never as the name of a function or variable.
  3 commentaires
Image Analyst
Image Analyst le 26 Fév 2023
Modifié(e) : Image Analyst le 26 Fév 2023
To expand on that, use
beta = asin((CD/BC) * sin(theta));
instead of
beta = asin((CD/BC)sin(theta));
If CD is actually the product of C and D instead of one variable name, then use
beta = asin(((C*D)/(B*C)) * sin(theta));
And if you want to work in degrees instead of radians, there are versions of those functions that end in d, like sind and asind
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
Walter Roberson
Walter Roberson le 26 Fév 2023
B C D E are not defined so BC cannot be B*C
The notation and formulas hint that BC is intended to be the magnitude of the distance between two points labeled B and C, typically points in two dimensions.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by