Asking about an output

조회 수: 1 (최근 30일)
Ritesh Khan
Ritesh Khan 2020년 3월 26일
편집: Stephen23 2020년 3월 26일
%% Differentiation of tan^{-1}x at 1
clear all;
clc;
f=@(x) atan(x);
a=1;
h=10.^[-2:-1:-4];
eVal=1/(1+a^2);
%% Forward difference formula
errf=zeros(length(h),1);
for i=1:length(h)
fDiff(i)=(f(a+h(i))-f(a))/h(i);
errf(i)=abs(eVal-fDiff(i));
end
disp(errf);
%% Central difference formula
errc=zeros(length(h),1);
for i=1:length(h)
fCen(i)=(f(a+h(i))-f(a-h(i)))/(2*h(i));
errc(i)=abs(eVal-fCen(i));
end
disp(errc);
%% Backward Difference formula
errb=zeros(length(h),1);
for i=1:length(h)
fBack(i)=(f(a)-f(a-h(i)))/h(i);
errb(i)=abs(eVal-fBack(i));
end
disp(errb);
The output is:
0.002491666914583
0.000249916666750
0.000024999166126
1.0e-05 *
0.833308332937044
0.008333328516130
0.000083316731292
0.002508333081242
0.000250083333320
0.000025000832460
My question is why the term 1.0e-05 * appearing?

채택된 답변

Stephen23
Stephen23 2020년 3월 26일
편집: Stephen23 2020년 3월 26일
"My question is why the term 1.0e-05 * appearing?"
Because you are displaying the values in the command window using long format. Change the format if you want to display the numbers using another format, e.g.:
>> format long
>> errc
errc =
1.0e-05 *
0.833308332937044
0.008333328516130
0.000083316731292
>> format long G
>> errc
errc =
8.33308332937044e-06
8.33332851613022e-08
8.33167312919159e-10
>> format short
>> errc
errc =
1.0e-05 *
0.8333
0.0083
0.0001
etc. If you want more format control than those offer then use fprintf.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by