prompt for variables in an equation

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

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Feb. 2012

1 Stimme

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 Kommentare

Ken
Ken am 26 Feb. 2012
Hi Walter,
That did it! Thank you.
Sorry about the email.
Daniel Bramhall
Daniel Bramhall am 22 Mai 2019
How do you break the loop when you get an answer?
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) )

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

0 Stimmen

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 Kommentare

Ken
Ken am 25 Feb. 2012
Thank you for your reply.
Where do I put the instruction input?
Walter Roberson
Walter Roberson am 26 Feb. 2012
At the point you have written "promp for r" and "promp for h"
Walter Roberson
Walter Roberson am 26 Feb. 2012
Please do not send clarifying questions in email: post them as comments.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by