prompt for variables in an equation

8 visualizaciones (últimos 30 días)
Ken
Ken el 25 de Feb. de 2012
Comentada: Walter Roberson el 23 de Mayo de 2019
Hello,
I am new here and to Matlab so here is my question. How do I promp a user for variables in an equation and after the answer is given to loop back again in order to enter new variable?
example:
promp for r
promp for h
r^2*acos((r-h)/r)-(r-h) * sqrt(2*r*h-h^2)
answer =
Loop

Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Feb. de 2012
while true
r = input('How about sending an r value over this way?');
h = input('Groovy. Got a spare h value too?');
r^2*acos((r-h)/r)-(r-h) * sqrt(2*r*h-h^2)
end
  3 comentarios
Daniel Bramhall
Daniel Bramhall el 22 de Mayo de 2019
How do you break the loop when you get an answer?
Walter Roberson
Walter Roberson el 23 de Mayo de 2019
while true
r = input('How about sending an r value over this way?');
if isscalar(r) && isnumeric(r); break; end
end
while true
h = input('Groovy. Got a spare h value too?');
if isscalar(h) && isnumeric(h); break; end
end
disp( r^2*acos((r-h)/r)-(r-h) * sqrt(2*r*h-h^2) )

Iniciar sesión para comentar.

Más respuestas (1)

Panagiotis Panos Katranitsas
Panagiotis Panos Katranitsas el 25 de Feb. de 2012
Hi Ken,
i think the instruction input is what you need.
ex.
reply = input('Do you want more? Y/N [Y]: ', 's');
if isempty(reply)
reply = 'Y';
end
  3 comentarios
Walter Roberson
Walter Roberson el 26 de Feb. de 2012
At the point you have written "promp for r" and "promp for h"
Walter Roberson
Walter Roberson el 26 de Feb. de 2012
Please do not send clarifying questions in email: post them as comments.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by