0

我正在尝试一个数字的自然对数,我收到消息:

tf2 = 60*ln(B1);

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

所以我尝试将数字转换为文档声称它将接受的浮点数,但随后我收到错误消息:

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'

所以然后我尝试将双打作为单打并得到相同的错误,但它说:

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'
4

2 回答 2

4

MATLAB 中的自然对数很简单log(x)。您正在混合两者:

您收到的错误消息是因为未定义该函数。您将收到与此行相同的错误:

bogus_function(1.23)
??? Undefined function or method 'bogus_function' for input arguments
of type 'double'.
于 2014-08-13T22:31:25.230 回答
0

我知道这是一个老问题,但是当我尝试这样做时我没有找到一个好的答案,所以我会为其他人写我的解决方案。

首先matlab中没有实现ln运算的函数,但是我们可以实现。请记住,对数基数的更改公式是

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

你可以很容易地检查这个。

如果你想计算 log 2 (8) 那么你需要做的是计算 log 10 (8)/log 10 (2) 你可以发现: log 2 (8) = log 10 (8)/log 10 ( 2) = 3 如果您想计算 ln(x),那么您只需将底数更改为 e。

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

所以,只需在matlab中编写该代码

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

您也可以将其作为函数并在需要时调用它,

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

*记住对数通式→对数基数(数)

于 2017-04-14T11:09:42.690 回答