MATLAB Answers

Help with while loop

1 view (last 30 days)
Hdez
Hdez on 26 Nov 2020
Commented: Hdez on 3 Dec 2020
I can't do this while loop properly, someone help me please?

  2 Comments

Rik
Rik on 26 Nov 2020
Why did you delete your previous question? It is the same as this one.
Hdez
Hdez on 3 Dec 2020
Thank you for your help

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 26 Nov 2020
dt = input('Enter the desired time step: ');
while dt >= h^2 / (4*alpha)
fprintf('solution is unstable\nPlease enter a value smaller than %g\n', h^2/(4*alpha));
dt = input('Enter the desired time step: ');
end

  0 Comments

Sign in to comment.


VBBV
VBBV on 26 Nov 2020
%f true
dt = input('Enter the desired time step: ');
while dt <= h^2 / (4*alpha)
disp('The solution is stable')
if dt >= h^2 / (4*alpha)
fprintf('solution is unstable\nPlease enter a value smaller than %g\n', h^2/(4*alpha));
dt = input('Enter the desired time step: ');
end
end
You have missing end for if condition

  1 Comment

VBBV
VBBV on 26 Nov 2020
you can as well follow Walters solution. Its fine as it compares the instability condition in while loop itself. If you don't see the message , Enter the desired time step again then it implies solution is automatically stable.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!