Plot Y derivative and find resulting X value minimum
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
, I have X and Y data as time and distance. I would like to find the derivative the Y values and plot this. Therefore yielding an acceleration time graph (2nd derivative). Next it is necessary to calculate the minimum of this curve. How do I find the derivative of the entire Y column to generate the new plot and then do I calculate the minimum with fminbnd? Thank yo.
採用された回答
Star Strider
2015 年 11 月 23 日
Use the gradient function to calculate the first derivative, the del2 function to calculate the second derivative, and the min function to find the minimum.
8 件のコメント
Gavin Seddon
2015 年 11 月 24 日
Thanks Star Strider, how do I plot the 2nd derivative?
My pleasure.
The results of both the gradient and del2 functions return vectors the same lengths as the input vector, so you would plot them as, for example:
t = linspace(0, 1);
y = exp(-5*t) .* sin(6*pi*t);
dydt = gradient(y,t);
d2ydt2 = del2(y,t);
figure(1)
plot(t, y*10)
hold on
plot(t, dydt)
plot(t, d2ydt2)
hold off
grid
legend('y(t) x 10', 'dy/dt', 'd^2y/dt^2')
I multiplied ‘y(t)’ by 10 in the plot, only to make it more easily visible.
many thanks, this appears perfect. I was thinking about the mathematics where:
derivative one then
derivative two then
plot 2 then
find 2 minimum value.
G.
My pleasure.
To get the minimum, use the min function, preferably with two outputs:
[d2_min, idx] = min(d2ydt2); % Minimum Of ‘d2ydt2’
t_min = t(idx); % Time At Minimum
. . . CODE . . .
plot(t_min, d2_min, 'bp') % Plot Minimum Of ‘d2ydt2’
This returns the minimum of the second derivative and the corresponding time it occurs. The plot call then plots the minimum with a blue five-pointed star. (You will have to put those in the appropriate places in your code.) You can also determine the corresponding values of your other data at the time the minimum of the second derivative occurs by referencing them with the ‘idx’ index variable, just as I did to determine ‘t_min’.
If there are several values equal to the minimum, the min function returns only the first one it finds. If you want all of them, use the find function.
Gavin Seddon
2015 年 11 月 30 日
Thank you, this appears extremely useful. When I used fminbnd the minimum was always at the maximum 1st derivative time. This prompted me to repeat the experiments to discount experimental error. It was then that I decided to use the 2nd derivative and avoid ambient changes. This method you have proposed analyses the results more completely. I am very grateful for your insight. Gavin.
Star Strider
2015 年 11 月 30 日
As always, my pleasure.
Gavin Seddon
2016 年 5 月 3 日
Hello Star Strider apologies for the long delay. I have been considering using the Z axes to show the second differential by plotting the first differential on it.
How would I take the first differential of the column Y values and append these new values into an additional column of the same table. I made then use the curve fitting tool to select the X, Y and Z axes? Gavin.
No worries.
I am not certain what you want to do. If you want to plot vectors in 3D, consider the plot3 function. Use the same independent variable, then plot each vector (function, first derivative, second derivative) as function so it. (I don’t have the Curve Fitting Toolbox, so I can’t help you with its functions.)
For example:
x = ...;
y = ...;
h = mean(diff(x));
d1y = gradient(y,h);
d2y = del2(y,h);
figure(1)
plot3(x,y, x,d1y, x, d2y)
grid on
legend('Function','First Derivative','Second Derivative')
I’m not certain what you want to do, but if I were to plot them in 3D, I would use plot3.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
