How to make M into a symsfun?

7 views (last 30 days)
Rydell Clyde
Rydell Clyde on 21 Sep 2022
Answered: Walter Roberson on 21 Sep 2022
% This program computes for the Tangent Line / Normal Line of a curve % about a given point
%define x for symbolic processing
syms x
%IDENTIFY the function f(x)
f(x) = 4*x^2 - 2*x + 1
%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=f(x0); %Evaluate y given value fo x
%FIND the slope function
yprime= diff(f) %Solve for the first derivative
%Determine the slope at the given x0
m = limit(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/ytangent
%I have to somehow input the value of x0 into yprime without making m into
%a syms because it affects the other equations. m = f'(c) where c=x0

Answers (1)

Walter Roberson
Walter Roberson on 21 Sep 2022
% This program computes for the Tangent Line / Normal Line of a curve % about a given point
%define x for symbolic processing
syms x
%IDENTIFY the function f(x)
f(x) = 4*x^2 - 2*x + 1
f(x) = 
%DETERMINE the point of tangency (This will be a random point)
syms x0
%SOLVE for the Ordinate of the point of tangency
y0=f(x0); %Evaluate y given value fo x
%FIND the slope function
yprime= diff(f) %Solve for the first derivative
yprime(x) = 
%Determine the slope at the given x0
m(x0) = limit(yprime,x,x0) %Evaluate the slope
m(x0) = 
%Solve the equation of the tangent line
ytangent= m*(x-x0) + y0
ytangent(x0) = 
%Solve the Equation of the normal line
ynormal= -1/ytangent
ynormal(x0) = 

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!