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 (최근 30일)
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

채택된 답변

Alan Stevens
Alan Stevens 2021년 11월 4일
< not <=
a = log10_bywhile( 50, 0.1 )
a = 1.7000
b = log10_bywhile( 100, 1 )
b = 2
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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by