How can I change the code to get a tangent in the graph
Show older comments
syms x y
f(x)=-(sin(x/2)); % Input the function and interval
Df=diff(f,x);
T(x)=Df*(x)
disp('Tangent lines of f(x) at origin');
disp(T(x));
fplot(f(x));
legend(T(x),'tangent');
grid on;
hold on;
xlabel('x'); ylabel('y');
title('Graph of the tangent line');
Answers (1)
Ameer Hamza
on 30 Nov 2020
Edited: Ameer Hamza
on 30 Nov 2020
Compare following code with your code to see the mistakes
syms x y
f(x)=-(sin(x/2)); % Input the function and interval
Df=diff(f,x);
T(x)=subs(Df,x,0)*x;
disp('Tangent lines of f(x) at origin');
disp(T(x));
fplot(f(x));
hold on
fplot(T(x))
legend({'curve', 'tangent'});
grid on;
xlabel('x'); ylabel('y');
title('Graph of the tangent line');

1 Comment
Shreesh Sahai
on 16 Jul 2021
Can I write a similar code if there's not a function, but a graph is obtained from observed data points?
Or, is there a way to find the function of a graph which has random data points?
Categories
Find more on Discrete Math 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!