Azzera filtri
Azzera filtri

Plot 2 Tangent Lines in a function

3 visualizzazioni (ultimi 30 giorni)
Fernando Moreno
Fernando Moreno il 17 Nov 2021
Risposto: Drishan Poovaya il 23 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])

Risposte (1)

Drishan Poovaya
Drishan Poovaya il 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])

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by