
matlab中不能直接求任意底数的对数对吧
1个回答
展开全部
不能但能计算E,2 ,10为底数的对数 其他的用那个间接计算么
function y=logn(x,n)
if x==0 | n==0
disp('warning:log of zero!');
y=NaN;
elseif n==1
disp('error:n==1');
else
if x<0 | n<0
disp('warning:the result will be imaginary!');
end
switch n
case exp(1)
y=log(x);
case 2
y=log2(x);
case 10
y=log10(x);
otherwise
y=log(x)/log(n);
end
end
function y=logn(x,n)
if x==0 | n==0
disp('warning:log of zero!');
y=NaN;
elseif n==1
disp('error:n==1');
else
if x<0 | n<0
disp('warning:the result will be imaginary!');
end
switch n
case exp(1)
y=log(x);
case 2
y=log2(x);
case 10
y=log10(x);
otherwise
y=log(x)/log(n);
end
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询