1

我喜欢使用 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>
4

1 回答 1

1

你的问题是你有两种不同的类型。如果我没记错的话,它只会在每个调用 div 类型中起作用linked:truemakeSagecell我没有尝试过其他任何方法,但是您的示例不起作用似乎是合理的-并且肯定可以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 上询问。

于 2013-04-19T12:41:10.150 回答