Can someone tell me how will I be able to remove the error in this script? I have already the answers but it says error.
2 views (last 30 days)
Show older comments
(For reference of the first photo)
5 Comments
Torsten
on 3 Oct 2022
Edited: Torsten
on 3 Oct 2022
syms x
%IDENTIFY the function f(x)
f = x^3-3*x+2
%DETERMINE the point of tangency (This will be a random point)
x0=randi([-5,5])
%SOLVE for the Ordinate of the point of tangency
y0=subs(f,x0) %Evaluate y given value fo x
%FIND the slope function
yprime =diff(f,x) %Solve for the first derivative
%Determine the slope at the given x0
m=subs(yprime,x,x0) %Evaluate the slope
%Solve the equation of the tangent line
ytangent= m*(x-x0)+y0
%Solve the Equation of the normal line
ynormal= (-1/m)*(x-x0)+y0
%DISPLAYING RESULTS
fprintf('The tangent line to f(x)=%s at (%.2f, %.2f) is y = %s \n',string(f),x0,y0, string(ytangent))
fprintf('The normal line to f(x)=%s at (%.2f, %.2f) is y = %s \n',string(f),x0,y0, string(ynormal))
Answers (0)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!