In: Computer Science
Plot the function y = 10 *(1 -exp(x/4)) over the interval 0 <x < xmax , using a for loop to determine the value of xmax such that y(xmax)=9.8. Properly label the plot. variable y is represents force in Newtons , and x represents time in second.
Matlab Code for the problem with plot obtained is provided below:
Code:
%set the initial x value
xval=0;
%the for loop to find the correct value of x
%that satisfies Y(x)= 9.8
%the loop iterate 200 times
for i= 1:1:200
%initialize the x vector with initial value of x
x(i)=xval;
%find the y value
%the y function should be y = 10 *(1 -exp(-x/4)) to get a
%positive x such that y(x)=9.8
yval= 10 *(1 - exp(-xval/4));
%add the y value to the y vector
y(i)=round(yval,1);
%if satisfied the requirement
if y(i)==9.8
%print the xmax and break
fprintf("The value of xmax = %f",xval)
break;
end
%update the x value
xval=xval+0.1;
end
%plot x,y
plot(x,y)
xlabel('Time (seconds)')
ylabel('Force (Newtons)')
Output:
Code screenshot: