1

私は SAGE を使って任意のコードを埋め込むのが好きです (以下の例)。しかし、この命令を使用して2つのセルをリンクしたいのですが、これは機能しません。どうすればこれを修正できますか?. たとえば、「計算」セルからセル「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

あなたの問題は、2 つの異なるタイプがあることです。私が間違っていなければ、各呼び出し div タイプ内linked:trueでのみ機能します。makeSagecell私は他に何も試していませんが、あなたの例がうまくいかないのは当然のことです - そして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>

問題が解決しない場合は、asagemath.org で質問することもできます。

于 2013-04-19T12:41:10.150 に答える