2013-04-19 2 views
1

저는 SAGE를 사용하여 코드를 삽입하는 것을 좋아합니다 (아래 예 참조). 하지만이 지시를 사용하여 연결된 두 개의 셀을 원하지만 작동하지 않습니다. 어떻게이 문제를 해결할 수 있을까요? 예를 들어 "mycell"셀에서 Hola() 함수를 "계산"하여 호출하려고합니다.Site + SAGE에 셀을 삽입하십시오

<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> 

답변

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에 문의하십시오.

+0

회신해도 감사하지만 아직 작동하지 않습니다. 'div.compute', 연결된 : 사실, evalButtonText : $ (함수() { //은 sagecell.makeSagecell가 ({inputLocation이 세이 세포 'mycell'ID를 가진 DIV 확인)} '평가를'; }});

Juan

관련 문제