
Matlab 阶乘函数
functionM=factorial(x)whilex>2M=x.*factorial(x-1)endifx==1M=1;endifx==0M=1;endifx<0di...
function M=factorial(x)
while x>2
M=x.*factorial(x-1)
end
if x==1
M=1;
end
if x==0
M=1;
end
if x<0
disp('应输入非负整数!');
end
One or more output arguments not assigned during call to 'C:\MATLAB7\work\factorial.m (factorial)'.
忘高手指正!! 展开
while x>2
M=x.*factorial(x-1)
end
if x==1
M=1;
end
if x==0
M=1;
end
if x<0
disp('应输入非负整数!');
end
One or more output arguments not assigned during call to 'C:\MATLAB7\work\factorial.m (factorial)'.
忘高手指正!! 展开
2个回答
展开全部
你是想自己编写一个程序是吧?那你要把factorial换个名字,比如factorial2,因为factorial是内部函数。
2015-06-01 · 知道合伙人教育行家
关注

展开全部
Matlab 阶乘函数factorial:
一、函数形式 :
Matlab中的阶乘函数是factorial,其函数形式为 factorial(N);
二、参数介绍:
当N为向量时,计算从1到N这N个数的乘积,即相当于prod(1:N);当N是N维数组时,计算N中每个元素的阶乘。注意:由于在Matlab中双精度浮点数的整数位数大约是15位,只有对不大于21的整数计算结果是精确的,对大于21的整数,factorial的计算结果只有前15位是准确的。
三、函数举例:
例子:同时计算 5,6,7,10的阶乘。
在Matlab命令窗口(Command Window)中,输入命令 y = factorial([5 6 7 10]) ;
运算结果为:120 720 5040 3628800,是数组中每个元素的阶乘。
一、函数形式 :
Matlab中的阶乘函数是factorial,其函数形式为 factorial(N);
二、参数介绍:
当N为向量时,计算从1到N这N个数的乘积,即相当于prod(1:N);当N是N维数组时,计算N中每个元素的阶乘。注意:由于在Matlab中双精度浮点数的整数位数大约是15位,只有对不大于21的整数计算结果是精确的,对大于21的整数,factorial的计算结果只有前15位是准确的。
三、函数举例:
例子:同时计算 5,6,7,10的阶乘。
在Matlab命令窗口(Command Window)中,输入命令 y = factorial([5 6 7 10]) ;
运算结果为:120 720 5040 3628800,是数组中每个元素的阶乘。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询