diff vs. gradient
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
Why does:
diffpressure = gradient(pressure)./gradient(density);
and
diffpressure = diff(pressure)./diff(density);
give drastically different results? The derivative using each method are completely different. See attached figure
採用された回答
2 投票
gradient uses central differences while diff(x) uses right-hand differences x(i+1)-x(i).
12 件のコメント
Benjamin
2018 年 11 月 5 日
Look at my attached figure, should they really be that different?
Matt J
2018 年 11 月 5 日
I don't see why not, but on the other hand the picture isn't all that informative. You should provide the input data in a .mat file.
Benjamin
2018 年 11 月 5 日
Check file now. It shows the original function, and the derivative using diff and derivative using grad. Surely, the derivative is not that sensitive to the method. I have hundreds of points on the curve.
Matt J
2018 年 11 月 5 日
I see no change in the attachment.
Benjamin
2018 年 11 月 5 日
Sorry, check now
You have only plotted one of the original functions. We cannot tell if this is density or pressure and without both we also cannot gain any insight into the ratio of their gradients.
Once again, the most helpful thing would be to attach your numeric data in a .mat file.
My preliminary guess would be that the gradient of density is tending toward zero, where the ratio calculation gradient(pressure)./gradient(density) becomes numerically unstable.
Benjamin
2018 年 11 月 5 日
The y-axis is pressure, x-axis is density. Ok, I'll try and attach, but quick question: If I have x values and yvalues, how would I differentiate y wrt to x? do I do diff(y)/diff(x) or just do diff(y) and plot it as plot(x,diff(y))
Benjamin
2018 年 11 月 5 日
Perhaps the better question is, if I have numerical X and Y data, what way should I differentiate y with respect to x?
Benjamin
2018 年 11 月 5 日
Do you think diff(y) / diff(x) is the way to go here?
Star Strider
2018 年 11 月 5 日
Yes!
If the X-data are not equi-spaced, use diff().
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
参考
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)
