Plot 2 Tangent Lines in a function

6 ビュー (過去 30 日間)
Fernando Moreno
Fernando Moreno 2021 年 11 月 17 日
回答済み: Alamanda Ponappa Poovaya 2021 年 11 月 23 日
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])

回答 (1 件)

Alamanda Ponappa Poovaya
Alamanda Ponappa Poovaya 2021 年 11 月 23 日
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])

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by