对数的matlab代码,Matlab的对数

数学中的lg表示是以10为底的对数,而自然对数表示为ln,也就是以e为底数的对数;但是在matlab中,log默认为e的对数,而如果需要其他的对数,则是log10,log2等等;例如:log10(10)=1等等。

rand - Uniformly distributed pseudorandom numbers

This MATLAB function returns a pseudorandom scalar drawn from the standard

uniform distribution on the open interval (0,1)

这里表示生成的数据是(0,1)之间的均匀分布的数值;

sign - Signum function

This MATLAB function returns an array Y the same size as X, where each element

of Y is:

Y = sign(X)

对于符号函数,在matlab中,不是使用sgn这种形式,而是使用sign的命令;

norm - Vector and matrix norms

This MATLAB function returns the 2-norm of input X and is equivalent to

norm(X,2).

n = norm(X)

n = norm(X,p)

对于矩阵以及向量的范数,其默认的情况下是表示二范数;

nargin - Number of function input arguments

This MATLAB function returns the number of input arguments passed in the call to

the currently executing function.

表示输入的变量个数;

同时这里需要指出matlab中和C语言中的switch命令的区别,其对于matlab来说,如下的命令:

input_num=input('Enter the number:');

switch input_num

case -1

disp('negative num');

disp('minus one');

case 0

disp('zero');

case 1

disp('positive num');

otherwise

disp('other number');

end

是正确的,而且其能够直接跳出,例如输入-1的时候,其不会显示zero等下面的输出语句;但是对于C语言来说,其正确的应该是:

switch(input_num)

{

case -1

disp('negative num'); disp('minus one'); break;

case 0

disp('zero');break;

case 1

disp('positive num');break;

default

disp('other number');break;(这个可以加也可以不加)

}(这个也可以不加)

这样才和matlab是一致的。主要是break那里的区别。

print - Print figure or save to file

This MATLAB function sends the contents of the current figure, including bitmap

representations of any user interface controls, to the printer using the device

and system printing command defined by printopt.

print

print('argument1','argument2',...)

print(handle,'filename')

print argument1 argument2 ... argumentn

这里主要是表示对图形的输出;

fprintf - Write data to text file

This MATLAB function applies the formatSpec to all elements of arrays A1,...An

in column order, and writes the data to a text file.

fprintf(fileID,formatSpec,A1,...,An)

fprintf(formatSpec,A1,...,An)

nbytes = fprintf(___)

这里主要是对于数据的输出;

input_num=input('Enter the number:');

if input_num>0

display('positive number');

fprintf('input_num=%f\n',input_num);

elseif input_num==0

display('zero');

fprintf('input_num=%f\n',input_num);

else input_num<0

display('negative number');

fprintf('input_num=%f\n',input_num);

end

注意可以有多个elseif语句,但是只能拥有一个if和end语句;并且disp以及display都可以使用。

对于循环来说,while循环的执行次数是不确定的,但是for循环所执行的次数是一致的。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值