Finding gradient of a part of a graph

42 ビュー (過去 30 日間)
Yen Tien Yap
Yen Tien Yap 2022 年 4 月 9 日
編集済み: Tala 2022 年 4 月 9 日
May I know how to find the gradient of the first linear part? What function should I use?

採用された回答

Sam Chak
Sam Chak 2022 年 4 月 9 日
編集済み: Sam Chak 2022 年 4 月 9 日
Technically, if is plotted by a function f(x) with a uniform step size h, then you can use the nabla = gradient(f)/h to compute the slope of f(x).
To find the gradient of the transient response, you need to pick a point in that region, for example, , and then find the index idx that is nearest to, or exactly at this point.
You can try @Faraz Hedayati's code or this code. Both are good learning experiences for you
h = 0.01;
x = 0:h:10;
y = 1 - exp(-x/sqrt(2)).*(cos(x/sqrt(2)) + sin(x/sqrt(2)));
plot(x, y)
hold on
nabla = gradient(y)/h;
[M, idx] = max(nabla);
plot(x(idx), y(idx), 'o', 'linewidth', 1.5)
m = nabla(idx) % slope at point p
c = y(idx) - m*x(idx) % y-intercept
z = m*x + c; % line equation at point p
plot(x, z, 'linewidth', 1.5)
hold off
grid on
xlabel('x')
ylabel('y')
title('y = f(x) and the tangent line at the steepest slope')
legend('function f(x)', 'the point at f(p)', 'tangent line', 'location', 'best')
Result:
Note: If the spread of the data points are not uniform, then you probably need to use the interpolation technique, interp1().

その他の回答 (1 件)

Tala
Tala 2022 年 4 月 9 日
編集済み: Tala 2022 年 4 月 9 日
A=your signal; dx=epsilon(2)-epsilon(1); % assuming the sampling frequency is constant
[M,I] = max(A);
B=diff(A(1:I))./dx;

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by