Display in the command window
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Manuel
le 15 Mai 2024
Réponse apportée : Image Analyst
le 15 Mai 2024
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 commentaires
Réponse acceptée
Athanasios Paraskevopoulos
le 15 Mai 2024
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 commentaires
Plus de réponses (1)
Image Analyst
le 15 Mai 2024
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 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!