# Plot 2 Tangent Lines in a function

1 view (last 30 days)
Im having problems while doing a function because I want to plot 2 tangent lines in x=1 and x=5 but Im not sure how to plot it, this is my current code
figure()
yline(0)
xline(0)
hold on
syms f(x)
f=15000*exp(x)^(-.6286*x)
f =
diff(f)
ans =
fplot (x,f, [0,10])
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (1)

Alamanda Ponappa Poovaya on 23 Nov 2021
Hi
Please have a look at the code snippet below. It calculates the tanget at points 1 and 5 and plots the tangents. Keep in mind that the tangent at 5 overlaps with your xline(0) hence it is not visually distinguishable
figure()
yline(0)
xline(0)
hold on
syms f(x)
f=15000*exp(x)^(-.6286*x);
fplot (x,f, [0,10])
dy(x)=diff(f,x);
% y = mx + c
% at 1
m = subs(dy,x,1);
m = double(m);
y = double(subs(f,x,1));
c = y - m*1;
syms t(x)
t = m*x + c;
fplot (x,t, [0,10])
% at 5
m = subs(dy,x,5);
m = double(m);
y = double(subs(f,x,5));
c = y - m*5;
syms t(x)
t = m*x + c;
fplot (x,t, [0,10])
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by