필터 지우기
필터 지우기

help i dont know why my code isnt working

조회 수: 1 (최근 30일)
jack
jack 2023년 2월 25일
댓글: Walter Roberson 2023년 2월 26일
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);

답변 (1개)

Walter Roberson
Walter Roberson 2023년 2월 26일
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
Image Analyst
Image Analyst 2023년 2월 26일
편집: Image Analyst 2023년 2월 26일
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 2023년 2월 26일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Block Considerations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by