Matlab. I want the codes to solve the lab, not the solution.
Finding Intervals of Increasing and Decreasing
My Solutions
Recall that if on a given interval, f is increasing on that interval and f' is positive, and f is decreasing on that interval and f' is negative. Analytically, we find those intervals using the following procedure: 1. Find the critical values where f' = 0 or f' is undefined. 2. Divide the x-axis into subintervals using these critical values. 3. Evaluate the derivative at a point in each subinterval to determine if it is positive or negative, which indicates whether f is increasing or decreasing on that subinterval.
Use this idea with the help of the program in the Solution Template to find the intervals where f is increasing and where it is decreasing. Then verify this by graphing the function using fplot in the interval [1,5].
Script
PS CReset MATLABO
syms x f
f = x^3;
df = diff(f); % no semicolon to see the derivative
cv = solve(df); % Find the critical values
% NOTE: there is no place here where f' does not exist
% DO NOT CHANGE CODE IN THIS SECTION
% Explanations in comments below each line
for i=1:length(cv)-1 % Test each subinterval one at a time
testpt = (cv(i) + cv(i+1))/2; % Average of the two endpoints will be between them
dfvalue(i) = subs(df,x,testpt); % Evaluate the derivative at this point
dersign = sign(double(dfvalue(i))); % Determine the sign of the derivative (-1 if negative, 1 if positive)
% Next lines display the interval and whether it is increasing or decreasing
disp([cv(i), cv(i+1)])
disp(' ')
if dersign == -1
disp('decreasing')
else
disp('increasing')
end
end
% Continue the for loop until all subintervals are tested
% Change this command to plot the original function on the stated interval
pf = fplot(f,[1,5]);
Assignment:
Testtore
Test for correct sign of final interval
Test for correct value of average derivative.