0

I am attempting to that the natural log of a number, I get the message:

tf2 = 60*ln(B1);

Undefined function 'ln' for input arguments of type 'double'.

So i try to cast the number as a float which the documentation claims it will accept but then i get the error message :

float(B1);

Error using float (line 50)
The input argument to float was not a supported type. The only recognized strings are     'single' and 'double'. The input type was 'double'

So then i try to cast the double as a single and get the same error but it says :

f=single(B1);
float(B1);

Error using float (line 50)
The input argument to float was not a supported type. The only recognized strings are     'single' and 'double'. The input type was 'single'
CSnewb
  • 147
  • 4
  • 13
  • 3
    `log` http://www.mathworks.com/help/matlab/ref/log.html – Yvon Aug 13 '14 at 22:25
  • You were calling Simulink's `float` http://www.mathworks.com/help/simulink/slref/float.html – Yvon Aug 13 '14 at 22:27
  • In simulink it's also `log` http://www.mathworks.com/help/simulink/slref/mathfunction.html – Yvon Aug 13 '14 at 22:32
  • I see it now ln() is MuPAD. http://www.mathworks.com/help/symbolic/mupad_ref/ln.html and the float was from simulink. The should make it a little more obvious which documentation your looking at, or im just not that used to it yet. – CSnewb Aug 13 '14 at 22:44

2 Answers2

4

The natural log in MATLAB is simply log(x). You're mixing the two:

The error message you get is because the function is not defined. You'll get the same error for this line:

bogus_function(1.23)
??? Undefined function or method 'bogus_function' for input arguments
of type 'double'.
Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
0

I know it's an old question but as I didn't find a good answer when I was trying to do it so I will write my solution for others.

First there is no implemented function to do ln operation in matlab, but we can make it. just remember that the change formula for log base is

log b (X)= log a (X)/log a (B)

you can check this easily.

if you want to calculate log 2 (8) then what you need to do is to calculate log 10 (8)/log 10 (2) you can find that: log 2 (8) = log 10 (8)/log 10 (2) = 3 So easily if you want to calculate ln(x), all you need is to change the base to the e.

ln(x) = log 10 (x)/log 10 (e)

so, just write that code in matlab

my_ln= log 10 ( number ) / log 10 ( exp(1) );

you can also make it as a function and call it whenever you need it,

function [val] = ln_fun(number)
val = log 10 (number)/ log 10 ( exp(1) );
end 

*remember the log general formula → log base (number)

Kamal El-Saaid
  • 145
  • 2
  • 11