Asking about an output

6 views (last 30 days)
Ritesh Khan
Ritesh Khan on 26 Mar 2020
Edited: Stephen23 on 26 Mar 2020
%% 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?

Accepted Answer

Stephen23
Stephen23 on 26 Mar 2020
Edited: Stephen23 on 26 Mar 2020
"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.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!