In: Mechanical Engineering
Plot the function y = 10(1 = e-x/4) over the interval 0 ≤ x ≤ xmax, using a while loop to determine the value of xmax such that y(xmax) = 9.8.
Properly label the plot. The variable y represents force in newtons, and the variable x represents time in seconds.
x = 0;
x_max = 0;
% infinite loop
while true
% calculate y
y = 10 *\r\n( 1 - exp(\r\n-x / 4 )\r\n);
% is the current value of x is the required xmax
if y >= 9.8
x_max = x;
break;
end
x = x + 0.01;
end
% create a vector x
x =\r\n[ 0 : 0.01 : x_max ];
% create a vector y
y = 10 .*\r\n( 1 - exp(\r\n-x ./ 4 )\r\n);
% set the title of the axis
title(\'Plot y = 10( 1 - exp(-x / 4) )\');
% set the label of the axis
xlabel(\'x\');
ylabel(\'y\');
grid on
hold
% plot the graph
plot( x , y );
Output:-
x = 0;
x_max = 0;
% infinite loop
while true