The log function does exactly what you want.
log(14 - y)
If you want a base 10 log, you use log10. There is also a log2 function, which gives a base 2 log. Other bases are achieved using the simple relation
log(X)/log(b)
produces a log to the base b. You could write a function for it as:
logb = @(X,b) log(X)/log(b);
logb(9,3)
ans =
2
which is as expected.
Finally, there is the reallog function, which also does the natural log, but it produces an error when the log would have been a complex number.
log(-2)
ans =
0.693147180559945 + 3.14159265358979i
reallog(-2)
Error using reallog
Reallog produced complex result.
But for the more normal case, reallog does the same thing as log.
log(2)
ans =
0.693147180559945
reallog(2)
ans =
0.693147180559945 Answer from John D'Errico on mathworks.com
MathWorks
mathworks.com › matlabcentral › fileexchange › 14866-logb
logb - File Exchange - MATLAB Central
September 1, 2016 - Examples: 1) To calculate the base 5 logarithm of 3: y = logb(3,5) 2) To calculate element-wise the log of a non-scalar input using different bases: y = logb(magic(3),[1 2 3; 4 5 6; 7 8 9]); See also: log, log10, log2 · Brett Shoelson (2025). ...
MathWorks
mathworks.com › matlabcentral › answers › 1465394-how-do-i-calculate-a-logarithm-of-a-variable-base
How do I calculate a logarithm of a variable base? - MATLAB Answers - MATLAB Central
October 2, 2021 - I saw that calculating log of the base of 10 or e is possible. for an example: after typing log (a,b) - I recieve an ERROR message. I'd like to use "a" as a varying number and change it using a loop until I'll get a good result. "a" can be for an example - 1.05, 1.003.... ... Too many input arguments. ... Sign in to comment. Sign in to answer this question. ... https://www.mathworks.com/matlabcentral/answers/1465394-how-do-i-calculate-a-logarithm-of-a-variable-base#answer_800204
MATLAB Central
mathworks.com › matlabcentral › cody › problems › 43311-how-to-calculate-log
How to calculate log? - MATLAB Cody - MATLAB Central
There is a log that have base 5. How to calculate? ... Calculate numerical integration. ... Find x in provided equation! ... Interpolate scattered data. ... Find the treasures in MATLAB Central and discover how the community can help you!
MathWorks
mathworks.com › matlab › mathematics › elementary math
Exponents and Logarithms - MATLAB & Simulink
In addition to common functions like exp and log, MATLAB® has several other related functions to allow flexible numerical calculations. The expm1 and log1p functions compensate for numerical round-off errors in small arguments, while the reallog, realpow, and realsqrt functions restrict the range of these functions to real numbers.
MathWorks
mathworks.com › matlabcentral › answers › 1808600-formula-for-changing-the-base-of-a-logarithm-is-loga-n-logb-n-logb-a-a-use-matlab-s-fu
formula for changing the base of a logarithm is: loga(N) = (logb(N))/(logb(a)) (a) Use MATLAB's function log (x) to cal... - MATLAB Answers - MATLAB Central
September 20, 2022 - formula for changing the base of a logarithm is:... Learn more about matlab, log
EDUCBA
educba.com › home › data science › data science tutorials › matlab tutorial › matlab log
Matlab log | Learn the different examples of Matlab log
March 8, 2023 - log10(5) [Passing 5 as an argument to the log10 method as we need its common logarithm] [Mathematically, the log of 5 to the base “10” is 0.6990] This is how our input and output will look like in the Matlab command window:
Call +917738666252
Address Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Top answer 1 of 5
17
Consider this example:
%# some random data
x = 2.^(0:10);
y = rand(size(x));
plot(log2(x), y) %# plot on log2 x-scale
set(gca, 'XTickLabel',[]) %# suppress current x-labels
xt = get(gca, 'XTick');
yl = get(gca, 'YLim');
str = cellstr( num2str(xt(:),'2^{%d}') ); %# format x-ticks as 2^{xx}
hTxt = text(xt, yl(ones(size(xt))), str, ... %# create text at same locations
'Interpreter','tex', ... %# specify tex interpreter
'VerticalAlignment','top', ... %# v-align to be underneath
'HorizontalAlignment','center'); %# h-aligh to be centered

2 of 5
15
You can plot directly using the plot command
plot (log2(x), y)
but then your x ticks will be the logarithm rather than the actual value. You could either just change your label
xlabel('Log (base 2) of quantity X');
or you can redo the ticks manually.
xt = get(gca, 'XTick');
set (gca, 'XTickLabel', 2.^xt);
Or you can be really fancy
xticks = 10:25;
set(gca, 'XTick', xticks);
for j = 1:length(xticks)
xtl{j} = ['2^' num2str(xticks(j))];
end
set(gca, 'XTickLabel', xtl)
which will evenly space the tick marks on the log scale, and label them according to their power of 2
MathWorks
mathworks.com › matlabcentral › answers › 52224-log-of-10-base-b-where-b-is-defined-as-1-to-10-in-increments-of-1
Log of 10 base "b" where 'b' is defined as 1 to 10 in increments of 1 - MATLAB Answers - MATLAB Central
October 29, 2012 - It is for school BTW, and all i know is Log(base'b')(X)=log(base'e')(x) over log(base'b'(b) where be is all values between 1-10. Sign in to comment. Sign in to answer this question. ... https://www.mathworks.com/matlabcentral/answers/52224-log-of-10-base-b-where-b-is-defined-as-1-to-10-in-increments-of-1#answer_63659
MathWorks
mathworks.com › matlab › mathematics › elementary math › exponents and logarithms
log - Natural logarithm - MATLAB
Y = log(X) returns the natural logarithm ln(x) of each element in array X.
MathWorks
mathworks.com › matlab › mathematics › elementary math › exponents and logarithms
log10 - Common logarithm (base 10) - MATLAB
Examine several values of the base 10 logarithm function. Calculate the common logarithm of 1. ... The result is 0, so this is the x-intercept of the log10 function. Calculate the common logarithm of 10. ... Calculate the common logarithm of 100. ... Calculate the common logarithm of 0. ... Create a vector of numbers in the interval [0.5 5].