我喜欢使用SAGE嵌入任何代码(例如下面的例子)。但我希望使用此指令链接两个单元格,但这不起作用。我怎么能解决这个问题? 例如,我尝试从“计算”单元格调用单元格“mycell”中的函数Hola()。
<script>
$(function () {
// Make the div with id 'mycell' a Sage cell
sagecell.makeSagecell({inputLocation: '#mycell',
evalButtonText: 'Evaluate'});
// Make *any* div with class 'compute' a Sage cell
sagecell.makeSagecell({inputLocation: 'div.compute',
linked: true,
evalButtonText: 'Evaluate'});
});
</script>
<div id="mycell">
<script type="text/x-sage">
def Hola():
print "Hola"
</script>
</div>
<div class="compute"><script type="text/x-sage">
Hola()
</script>
</div>
答案 0 :(得分:1)
您的问题是您有两种不同的类型。如果我没有弄错的话,linked:true
只能在每个makeSagecell
调用div类型中使用。我还没有尝试过任何其他方法,但是你的例子不起作用似乎是合理的 - linked:true
肯定 与同一个班级中的所有人合作,或者我今天的讲义不会工作!
编辑:这是我的工作,或者至少是一个例子。这似乎工作正常。
$(function () {
// Make *any* div with class 'compute' a Sage cell
sagecell.makeSagecell({inputLocation: 'div.compute',
evalButtonText: 'Evaluate',
linked:true});
});
[snip]
<div class="compute"><script type="text/x-sage">
def r2(n):
n = prime_to_m_part(n,2)
F = factor(n)
ret = 4
for a,b in F:
if a%4==3:
if b%2==1:
return 0
else:
n = prime_to_m_part(n,a)
else:
ret = ret * (b+1)
return ret
def L(n):
ls = []
out = 0
for i in range(1,n+1):
out += r2(i)
ls.append((i,out/i))
return ls
</script></div>
<div class="compute"><script type="text/x-sage">
@interact
def _(n=100):
P = line(L(n))
P += plot(pi+pi*sqrt(2)/sqrt(x),x,3,n,color='red')
P += plot(pi-pi*sqrt(2)/sqrt(x),x,3,n,color='red')
P += plot(pi,x,3,n,color='red',linestyle='--')
show(P)
</script></div>
如果你继续遇到麻烦,我也会问ask.sagemath.org。