Display in the command window
2 次查看(过去 30 天)
显示 更早的评论
my code looks as follows but i don't understand why the values of x and z won't display on the command window. The values are supposed to plot a semicircle.
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 150;
maxConstraintX = 50;
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue - radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) - startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp(['x: ', num2str(x), ', z: ', num2str(z)]);
end
end
end
0 个评论
采纳的回答
Athanasios Paraskevopoulos
2024-5-15
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 50; % Swapped values
maxConstraintX = 150; % Swapped values
minConstraintZ = 10;
maxConstraintZ = 300;
for x = (startUpValue - radius) : 0.25 : (startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = startUpHeight - sqrt(radius^2 - ((x - startUpValue)^2)); % Corrected formula for z
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
disp(['x: ', num2str(x), ', z: ', num2str(z)]);
end
end
end
0 个评论
更多回答(1 个)
Image Analyst
2024-5-15
You swapped the min and max x constraints. Even when I fix those, the z constraint is not met. I threw in some debug messages so you can see what's going on:
startUpHeight = 299.07;
startUpValue = 100;
radius = 15;
minConstraintX = 50;
maxConstraintX = 150;
minConstraintZ = 10;
maxConstraintZ = 300;
z = 0;
for x = (startUpValue - radius):0.25:(startUpValue + radius)
if ((maxConstraintX >= x) && (x >= minConstraintX))
z = -1*((sqrt(radius^2)-((x-(3*radius))^2)) - startUpHeight);
if ((maxConstraintZ >= z) && (z >= minConstraintZ))
% Constraints met
fprintf('Both X and Z Constraints ARE met. x: %f, z: %f\n', x, z);
else
% Z Constraints not met:
fprintf('Z Constraint IS NOT met. x: %f, z: %f\n', x, z);
end
else
% X Constraints not met:
fprintf('X Constraint IS NOT met. x: %f, z: %f\n', x, z);
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!