How to use a while loop to achieve the maximum value of a plot?

Hi guys, I'm having a hard time solving this particular problem;
Plot the function y=10(1-e^-x/4) using a while loop for the interval 0≤ x ≤ xmax, xmax should be the value of where y(xmax)=9.8.
I would appreciate some help!

Answers (2)

x=0;
y=0;
%% Flowing code just find the xmax where y<9.8
while y<9.8
y=10*(1-exp(-x/4));
x=x+0.1;
end
% The output of the above code is x, which is xmax
xmax=x;
%% Plot y, where x varies from 0 to xmax
x=0:.1:xmax;
y=10*(1-exp(-x/4));
plot(x,y);
x = 0;
yx = y(x);
while yx < 9.8
x = x + randn();
yx = y(x);
end
x is now an upper bound for xmax, and you have used a while loop in your calculation, so once you have done this, you can switch to more useful methods.

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 1 May 2019

Edited:

on 1 May 2019

Community Treasure Hunt

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

Start Hunting!