Plot 2 Tangent Lines in a function

6 views (last 30 days)
Fernando Moreno
Fernando Moreno on 17 Nov 2021
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])

Answers (1)

Alamanda Ponappa Poovaya
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])

Categories

Find more on Line Plots 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!