Solving calculus using MATLAB: Finding the equation of the tangent line and normal line of the given equation at the given point. Graphing the function and lines.
f(x) = x^3 - 3x + 21.
1. Determine the point of tangency.
2. Solve for the ordinate of the point of tangency.
3. Find the slope function.
4. Determine the slope at the given x0.
5. Solve the equation of the tangent line.
6. Solve for the equation of the normal line.
MATLAB Exercise No.2 (MLab 2)
MATLAB Activity:
IDENTIFY the function f(x):
f(x) = x^3 - 3x + 2
DETERMINE the point of tangency (This will be a random x0):
randi([-5,5])
SOLVE for the ordinate of the point of tangency:
y0 = f(x0) (Evaluate y given value for x)
FIND the slope function:
yprime = (Solve for the first derivative)
DETERMINE the slope at the given x0:
w = (Evaluate the slope)
SOLVE the equation of the tangent line:
ytangent = (Equation of the tangent line)
SOLVE for the equation of the normal line:
ynormal = (Equation of the normal line)
DISPLAYING RESULTS:
fprintf("The tangent line to f(x) = %s at %.2f is y = %.2f\n", x0, ytangent)
fprintf("The normal line to f(x) = %s at %.2f, %.2f is y = %.2f\n", x0, ynormal)
PLOTTING:
g1 = ezplot(f, [-15,15])
set(g1, 'color', 'b')
grid on
hold on
plot(x0, y0, 'r*')
text(x0+1, y0, "Point of Tangency")
g2 = ezplot(ytangent, [-15,15])
text(5, 5, ['y(Tangent) = ', string(ytangent)])
pause(1)