Maple 执行中的这些底片来自哪里?
Where are these negatives coming from in Maple execution?
我有兴趣模拟"regression to the mean"的现象。如果 V 中 1 的数量大于 N/2 + 5*sqrt(N).
,则长度为 N 的 0-1 向量 V 为 "gifted"
我希望 Maple 评估一串 M 0-1 列表,每个列表的长度为 N,以确定它们是否有天赋。
然后,鉴于列表 V[i] 有天赋,我想评估列表 V[i+1] 有天赋的概率。
到目前为止,我的代码以一种奇怪的方式失败了。到目前为止,所有代码应该做的是创建总和列表(称为 'total')和列表 'g' 如果 total[i] <= N/2 + 5sqrt( N),否则为 1。
代码如下:
RS:=proc(N) local ra,i:
ra:=rand(0..1):
[seq(ra(),i=1..N)]:
end:
Gift:=proc(N,M) local total, i, g :
total:=[seq(add(RS(N)),i=1..M)]:
g:=[seq(0,i=1..M)]:
for i from 1 to M do
if total[i] > (N/2 + 5*(N^(1/2))) then
g[i]:=1
fi:
od:
print(total, g)
end:
麻烦的是,当我尝试 Gift(100,20) 时,Maple 响应,
"Error, (in Gift) cannot determine if this expression is true or false: 5*100^(1/2) < -2"
或者,当我尝试 Gift(10000,20), "Error, (in Gift) cannot determine if this expression is true or false: 5*10000^(1/2) < -103."
这些负数是从哪里来的? 为什么 Maple 不能判断 5(10000)^{1/2} < -103 与否?
来自枫树online help:
Important: The evalb command does not simplify expressions. It may return false for a relation that is true. In such a case, apply a simplification to the relation before using evalb.
...
You must convert symbolic arguments to floating-point values when using the evalb command for inequalities that use <, <=, >, or >=.
在此特定示例中,Maple 在尝试确定符号平方根是否小于 -2 时卡住,尽管它在退出前已尽力简化。
一个解决方法是对不等式应用 evalf。而不是 evalb(x < y)
,你会写 evalb(evalf(x < y))
.
至于为什么 Maple 不能处理这些不等式,我不知道。
负数只是不等式的一部分,当带有部首的部分移到一侧而纯有理部分移到另一侧时产生的不等式。
使用适当的机制解决条件测试。例如,
if is( total[i] > (N/2 + 5*N^(1/2)) ) then
...etc
或者说,
temp := evalf(N/2 + 5*N^(1/2));
for i from 1 to M do
if total[i] > temp then
...etc
我有兴趣模拟"regression to the mean"的现象。如果 V 中 1 的数量大于 N/2 + 5*sqrt(N).
,则长度为 N 的 0-1 向量 V 为 "gifted"我希望 Maple 评估一串 M 0-1 列表,每个列表的长度为 N,以确定它们是否有天赋。 然后,鉴于列表 V[i] 有天赋,我想评估列表 V[i+1] 有天赋的概率。
到目前为止,我的代码以一种奇怪的方式失败了。到目前为止,所有代码应该做的是创建总和列表(称为 'total')和列表 'g' 如果 total[i] <= N/2 + 5sqrt( N),否则为 1。
代码如下:
RS:=proc(N) local ra,i:
ra:=rand(0..1):
[seq(ra(),i=1..N)]:
end:
Gift:=proc(N,M) local total, i, g :
total:=[seq(add(RS(N)),i=1..M)]:
g:=[seq(0,i=1..M)]:
for i from 1 to M do
if total[i] > (N/2 + 5*(N^(1/2))) then
g[i]:=1
fi:
od:
print(total, g)
end:
麻烦的是,当我尝试 Gift(100,20) 时,Maple 响应, "Error, (in Gift) cannot determine if this expression is true or false: 5*100^(1/2) < -2" 或者,当我尝试 Gift(10000,20), "Error, (in Gift) cannot determine if this expression is true or false: 5*10000^(1/2) < -103."
这些负数是从哪里来的? 为什么 Maple 不能判断 5(10000)^{1/2} < -103 与否?
来自枫树online help:
Important: The evalb command does not simplify expressions. It may return false for a relation that is true. In such a case, apply a simplification to the relation before using evalb.
...
You must convert symbolic arguments to floating-point values when using the evalb command for inequalities that use <, <=, >, or >=.
在此特定示例中,Maple 在尝试确定符号平方根是否小于 -2 时卡住,尽管它在退出前已尽力简化。
一个解决方法是对不等式应用 evalf。而不是 evalb(x < y)
,你会写 evalb(evalf(x < y))
.
至于为什么 Maple 不能处理这些不等式,我不知道。
负数只是不等式的一部分,当带有部首的部分移到一侧而纯有理部分移到另一侧时产生的不等式。
使用适当的机制解决条件测试。例如,
if is( total[i] > (N/2 + 5*N^(1/2)) ) then
...etc
或者说,
temp := evalf(N/2 + 5*N^(1/2));
for i from 1 to M do
if total[i] > temp then
...etc