How to numerically differentiate provided data?

2 ビュー (過去 30 日間)
Lingbai Ren
Lingbai Ren 2021 年 9 月 15 日
コメント済み: Lingbai Ren 2021 年 9 月 24 日
I have the measurements of x with corresponding y displacement lengths:
x = [0,0.375,0.75,1.125,1.5,1.875,2.25,2.625,3];
y = [0,-0.2571,-0.9484,-1.9689,-3.2262,-4.6414,-6.1503,-7.7051,-9.275];
and dy/dx = theta(x) >> theta is the slope
My question is how to numerically differentiate the provided data for displacement y(x)
and the hint is I can choose formulas of any error order.
It's a question combined both math and numerical method, can any one give some help?

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 15 日
x = [0,0.375,0.75,1.125,1.5,1.875,2.25,2.625,3];
y = [0,-0.2571,-0.9484,-1.9689,-3.2262,-4.6414,-6.1503,-7.7051,-9.275];
theta = gradient(x,y)
theta = 1×9
-1.4586 -0.7908 -0.4381 -0.3293 -0.2806 -0.2565 -0.2448 -0.2400 -0.2389
plot(x, y, x, theta)
legend({'x', 'theta'})
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 15 日
x = [0,0.375,0.75,1.125,1.5,1.875,2.25,2.625,3];
y = [0,-0.2571,-0.9484,-1.9689,-3.2262,-4.6414,-6.1503,-7.7051,-9.275];
orders = 1:7;
for order = orders
p = polyfit(x, y, order);
predict = polyval(p, x);
plot(x, predict, 'displayname', "order = " + order);
hold on
err(order-min(orders)+1) = sum((predict - y).^2);
end
xlabel('x'); ylabel('y predicted')
legend show
figure(2)
plot(orders, err);
xlabel('polynomial order'); ylabel('sse')
Lingbai Ren
Lingbai Ren 2021 年 9 月 24 日
Thanks Walter! Sorry for the late reply!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by