diff makes M less than what i want by 1 elment and i want to have second derivaitve numircal

1 回表示 (過去 30 日間)
amr haggag
amr haggag 2019 年 12 月 10 日
コメント済み: Adam Danz 2019 年 12 月 10 日
figure(4)
E=(k.^2)*(1.0540^2)/(2*1000*9.1);
fx=diff(E)./diff(k);
fxx=fx./diff(k);
M=((1.054^2)*(1000))./fxx;
plot(k,M);
Error using plot
Vectors must be the same length.
Error in Untitled4 (line 17)
plot(k,M);
  1 件のコメント
Adam Danz
Adam Danz 2019 年 12 月 10 日
Y = diff(X) acts on vector x by subtracting element m+1 from element m. So, if x is
x = [3 2 7 4 1];
then Y will be
y = [2-3, 7-2, 4-7, 1-4]
= [-1, 5, -3, -3]
There will always be one less element in Y than in X.
To compute the numerical gradient at each point in x rather than between points, use

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

回答 (1 件)

Star Strider
Star Strider 2019 年 12 月 10 日
Use the gradient function.
Specifically:
k = 0:0.1:5;
figure(4)
E=(k.^2)*(1.0540^2)/(2*1000*9.1);
fx=gradient(E)./gradient(k);
fxx=fx./gradient(k);
M=((1.054^2)*(1000))./fxx;
plot(k,M);

カテゴリ

Help Center および File ExchangeGraphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by