How do I ensure the user inputs a minimum x value that's actually smaller than the maximum x value?

1 vue (au cours des 30 derniers jours)
Alexis Williams le 18 Avr 2021
Commenté : Alexis Williams le 18 Avr 2021
I am trying to get the user's minimum and maximum x values for the quadratic equation, but I don't know how to code to make sure that the minimum value doesn't equal or exceed the maximum value. Please help.
% Plotting a User-Entered Quadratic Function %
user_input = input(['Enter a, b, and c values for the quadratic equation',...
'\nax^2 + bx + c = 0. Input all three values in this form [a b c].',...
'\nInput values (including brackets): ']);
user_input1 = input(['Enter the minimum and maximum values of x in',...
'\nthe form [a b]: ']);
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

David Fletcher le 18 Avr 2021
isError = 1;
while isError
user_input1 = input(['Enter the minimum and maximum values of x in',...
'\nthe form [a b]: ']);
isError = ~(user_input1(1)<user_input1(2));
end
1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Alexis Williams le 18 Avr 2021
Thank you! This helped a lot.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics 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!

Translated by