フィルターのクリア

If I had the derivative of an equation and had data points how would I plot them

2 ビュー (過去 30 日間)
My derivative is 1 - (sin(x))/(2√(x)) - (√x)(cos(x)) and x = [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0] how would I plot them?

採用された回答

Torsten
Torsten 2022 年 10 月 2 日
d = @(x)1 - sin(x)./(2*sqrt(x)) - sqrt(x).*cos(x);
x = [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0];
plot(x,d(x))
  2 件のコメント
Batuhan Yildiz
Batuhan Yildiz 2022 年 10 月 2 日
編集済み: Image Analyst 2022 年 10 月 2 日
Two Questions:
  1. why add the @(x)?
  2. would this code also work?
x=[1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0] ;
y=x-sqrt(x).*sin(x);
dy=diff(y)./diff(x);
plot(x(2:end),dy);
Torsten
Torsten 2022 年 10 月 2 日
編集済み: Torsten 2022 年 10 月 2 日
why add the @(x)?
I defined the derivative d as a function. Alternatively, you can of course use
x = [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0];
d = 1 - sin(x)./(2*sqrt(x)) - sqrt(x).*cos(x);
plot(x,d)
would this code also work?
If you are too lazy to compute the exact derivative, you can use the approximation
dy = diff(y)./diff(x)
formed by finite difference quotients.
But note that d gives you an approximate derivative in points (x(1:end-1)+x(2:end))/2, not in x(2:end). Thus for the plot you should use
plot((x(1:end-1)+x(2:end))/2,dy)
instead of
plot(x(2:end),dy)
Alternatively, you can compute the derivative symbolically:
syms x
y = x-sqrt(x).*sin(x);
dy = diff(y,x)
dy = 

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 10 月 2 日
if you have numeric derivative and you want to plot the original curve (to within a constant shift) then use cumtrapz() and plot that.

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by