Calculate derivative using central differencing
1 view (last 30 days)
Show older comments
Kyle Lazaroff
on 20 Nov 2019
Commented: Kyle Lazaroff
on 20 Nov 2019
dx = 0.01;
x = 0:dx:2*pi;
signal = sin(x).*cos(10*x);
dsignaldx_true = cos(x).*cos(10*x) - 10*sin(x).*sin(10*x);
dsignaldx_forward = ForwardO1(signal, x);
dsignaldx_central =
for i =
end
error_forward_max = max(abs(dsignaldx_forward(2:end-1) - dsignaldx_true(2:end-1)));
fprintf('The maximum relative error encountered when using forward differencing with O(dx) error is %f\n', error_forward_max)
error_central_max =
fprintf('The maximum error encountered when using central differencing with O(dx^2) error is %f\n', error_central_max)
error_forward_average = mean(abs(dsignaldx_forward(2:end-1) - dsignaldx_true(2:end-1)));
fprintf('The average error encountered when using forward differencing with O(dx) error is %f\n', error_forward_average)
error_central_average =
fprintf('The average error encountered when using central differencing with O(dx^2) error is %f\n', error_central_average)
0 Comments
Accepted Answer
KALYAN ACHARJYA
on 20 Nov 2019
Edited: KALYAN ACHARJYA
on 20 Nov 2019
Is this?
dx=0.01;
x=0:dx:2*pi;
signal=sin(x).*cos(10*x);
diff_cen=(sin(x+dx).*cos(10*(x+dx))-sin(x).*cos(10*x))/(2*dx);
diff_cen
# I hope, rest you will do
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!