I want Estimate log to the base 10 value using 'x' number such that 10^estimated value is equal to or just exceeding x.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Manav Divekar
am 4 Nov. 2021
Kommentiert: Manav Divekar
am 4 Nov. 2021
function [out] = log10_bywhile(x, inc)
esmt = 0;
if ~exist('inc','var')
inc = 0.01;
end
inc1 = 0;
while esmt <=x
esmt = 10^inc1;
inc1 = inc1+inc;
end
out = inc1-inc;
This is the i wrote to calculate the estimated value for log10 but, for log10 of 100 I should be getting 2 as output as it is a perfect value.
>> log10_bywhile( 50, 0.1 ) % Correct output
ans =
1.7000
>> log10_bywhile( 100, 1 ) % Wrong Output
ans =
3
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 4 Nov. 2021
< not <=
a = log10_bywhile( 50, 0.1 )
b = log10_bywhile( 100, 1 )
function [out] = log10_bywhile(x, inc)
esmt = 0;
% if ~exist('inc','var')
% inc = 0.01;
% end
inc1 = inc;
while esmt < x %%%%%%%%%%%%%%%%%%
esmt = 10^inc1;
inc1 = inc1+inc;
end
out = inc1-inc;
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Logging finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!