Calculate derivative using central differencing
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
KALYAN ACHARJYA
2019년 11월 20일
편집: KALYAN ACHARJYA
2019년 11월 20일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!