Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Why this code is error???

1 回表示 (過去 30 日間)
Jukkrid Boonlkom
Jukkrid Boonlkom 2018 年 2 月 15 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
clc,clear all,close all;
x = [0 1 2 3];
y = [0 1 2 3];
f3 = 6./(factorial(x).*factorial(3-x));
f4 = 24./(factorial(y).*factorial(4-y));
f5 = 120./(factorial(3+(-x)+(-y)).*factorial(2+x+y));
mpd = (f3.*f4.*f5)./220;
stem3(x,y,mpd);
xlabel('x'); ylabel('y'); zlabel('mpd');
  2 件のコメント
Jukkrid Boonlkom
Jukkrid Boonlkom 2018 年 2 月 15 日
If I wanted to make x + y> 3 to f5 = 1, then how to do?
RB Blackstone
RB Blackstone 2018 年 2 月 16 日
This part of the equation produced negative integers.
>> 3+-x+-y
Ans = 3 1 -1 -3
Factorial() requires non-negative integers.

回答 (1 件)

C.J. Harris
C.J. Harris 2018 年 2 月 15 日
Because given your definitions of x and y, the expression 3+(-x)+(-y) results in [3 1 -1 -3], and you cannot calculate the factorial of a negative number.
  2 件のコメント
Jukkrid Boonlkom
Jukkrid Boonlkom 2018 年 2 月 15 日
編集済み: Jukkrid Boonlkom 2018 年 2 月 15 日
So what should I do? Can I change 3-x-y?
Jan
Jan 2018 年 2 月 16 日
@Jukkrid Boonlkom: How could the readers know, what you want to do. All we see is the failing code, which cannot work for mathematical reasons. This does not allow to suggest a modification, because you did not tell yet, what you want to calculate.

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by