except:
 _st_.goboom(_sage_const_278 )
_st_.blockbegin()
try:
  n=_sage_const_4 
  h=_sage_const_1 /_sage_const_5 
  tk=[h*i for i in range(n)]
  yk=range(n)
  yk[_sage_const_0 ]=_sage_const_1 
  # Tính bằng công thức lặp
  #for i in range(n-1):
  #  yk[i+1]=yk[i]+h*(yk[i]+tk[i])
  # Tính bằng Euler solver có sẵn trong Sage
  t,y=var('t y')
  from sage.calculus.desolvers import eulers_method
  zk1=eulers_method(t+y,tk[_sage_const_0 ],yk[_sage_const_0 ],h,tk[_sage_const_0 ]+h*(n-_sage_const_1 ),algorithm="none")
  #yk=[[j] for i,j in zk1] # Báo lỗi phía sau: lệnh latex(round(yk[i],3)) không thực hiện được (TypeError: a float is required), vì dấu [] tạo ra matrix chứ không phải list
  yk=[j for i,j in zk1]
  # Tạo table trong Latex
  tableEuler=r"\begin{tabular}{l|c|l}"
  tableEuler+=r"$k$ & $t_k$ & $y_k$ \\ \hline"
  for i in range(n):
    tableEuler+=latex(i) + r"&" + latex(round(tk[i],_sage_const_1 )) + r"&" + latex(round(yk[i],_sage_const_4 )) + r"\\"
  tableEuler+=r"\end{tabular}"
except:
 _st_.goboom(_sage_const_328 )
_st_.blockend()
try:
 _st_.inline(_sage_const_14 , tableEuler)
except:
 _st_.goboom(_sage_const_330 )
Exemplo n.º 2
0
_st_.blockbegin()
try:
    n = _sage_const_4
    h = _sage_const_1 / _sage_const_10
    tk = [_sage_const_1 + h * i for i in range(n)]
    yk = range(n)
    yk[_sage_const_0] = _sage_const_1
    # Tính bằng công thức lặp
    #for i in range(n-1):
    #  yk[i+1]=yk[i]+h*(yk[i]+tk[i])
    # Tính bằng Euler solver có sẵn trong Sage
    t, y = var('t y')
    from sage.calculus.desolvers import eulers_method
    zk1 = eulers_method(y / t - _sage_const_1,
                        tk[_sage_const_0],
                        yk[_sage_const_0],
                        h,
                        tk[_sage_const_0] + h * (n - _sage_const_1),
                        algorithm="none")
    #yk=[[j] for i,j in zk1] # Báo lỗi phía sau: lệnh latex(round(yk[i],3)) không thực hiện được (TypeError: a float is required), vì dấu [] tạo ra matrix chứ không phải list
    yk = [j for i, j in zk1]
    # Tạo table trong Latex
    tableEuler = r"\begin{tabular}{l|c|l}"
    tableEuler += r"$k$ & $t_k$ & $y_k$ \\ \hline"
    for i in range(n):
        tableEuler += latex(i) + r"&" + latex(
            round(tk[i], _sage_const_1)) + r"&" + latex(
                round(yk[i], _sage_const_4)) + r"\\"
    tableEuler += r"\end{tabular}"
except:
    _st_.goboom(_sage_const_341)
_st_.blockend()
    n = _sage_const_4
    h = _sage_const_1 / _sage_const_10
    tk = [_sage_const_1 + h * i for i in range(n)]
    yk = range(n)
    yk[_sage_const_0] = _sage_const_1
    # Tính bằng công thức lặp
    # for i in range(n-1):
    #  yk[i+1]=yk[i]+h*(yk[i]+tk[i])
    # Tính bằng Euler solver có sẵn trong Sage
    t, y = var("t y")
    from sage.calculus.desolvers import eulers_method

    zk1 = eulers_method(
        y / t - _sage_const_1,
        tk[_sage_const_0],
        yk[_sage_const_0],
        h,
        tk[_sage_const_0] + h * (n - _sage_const_1),
        algorithm="none",
    )
    # yk=[[j] for i,j in zk1] # Báo lỗi phía sau: lệnh latex(round(yk[i],3)) không thực hiện được (TypeError: a float is required), vì dấu [] tạo ra matrix chứ không phải list
    yk = [j for i, j in zk1]
    # Tạo table trong Latex
    tableEuler = r"\begin{tabular}{l|c|l}"
    tableEuler += r"$k$ & $t_k$ & $y_k$ \\ \hline"
    for i in range(n):
        tableEuler += (
            latex(i) + r"&" + latex(round(tk[i], _sage_const_1)) + r"&" + latex(round(yk[i], _sage_const_4)) + r"\\"
        )
    tableEuler += r"\end{tabular}"
except:
    _st_.goboom(_sage_const_382)