Find the value of x when the first derivative is equal to 0

23 ビュー (過去 30 日間)
Angelavtc
Angelavtc 2022 年 1 月 10 日
コメント済み: Angelavtc 2022 年 1 月 10 日
Hello community,
I have the data x, y (.mat version) from which I compute its first derivative as follows :
dy = diff(y)./diff(x);
I need to find the points (x, y) such that the first derivative is 0. (In this case, there should be 2 points)
I have tried with this code, but it doesn't work, it tells me "Second argument must be a vector of symbolic variables"
solve(dy==0,x)
Any idea how to fix the problem?
Thanks in advance!

採用された回答

Torsten
Torsten 2022 年 1 月 10 日
編集済み: Torsten 2022 年 1 月 10 日
x = -pi/2:0.01:pi/2;
y = cos(x);
dydx = diff(y)./diff(x);
[~,idx] = min(dydx.^2);
xmin = (x(idx+1)+x(idx))/2
xmin is the point with slope closest to 0.
  3 件のコメント
Angelavtc
Angelavtc 2022 年 1 月 10 日
@Torsten I understand. With the squared derivative, the negative values become positive and the minimum is 0, the value we are looking for. Thank you very much :)

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by