# How to display a function with the values of the variables? Anonymous For the generation of worksheets I need to know, if its possible to show a function with the assigned values? What could be a process to do that?

My hope is to generate a output like: (lamda_z,s_k) |--> lambda_z * s_k = 5 * 4 = 20

\begin{sagesilent}
tension (lambda_z, s_k) = lambda_z * s_k
lambda_za = 5
s_ka = 4

\end{sagesilent}
$\sage {tension (lambda_za, s_ka)}$
\end{document}


thank you

edit retag close merge delete

Sort by » oldest newest most voted

\begin{sagesilent}
tension (lambda_z, s_k) = lambda_z * s_k
lambda_za = 5
s_ka = 4

\end{sagesilent}
$\sage {tension} = \sage{tension (lambda_za, s_ka)}$
\end{document}


You won't get the 5*4 output, but you'll get the definition of the function, at least.

more
\documentclass[a4paper]{article}

\usepackage{amsmath}
\usepackage{sagetex}

\newcommand{\tension}{\operatorname{tension}}

\begin{document}
\pagestyle{empty}

\begin{sagesilent}
tension(lambda_z, s_k) = lambda_z * s_k
lambda_za = 5
s_ka = 4
s = str(tension(lambda_z,s_k))
ss = s.replace('lambda_z','\lambda_z')
sss = s.replace('lambda_z',str(lambda_za)).replace('s_k',str(s_ka))
\end{sagesilent}

Evaluating the function
$$\tension : \sage{tension}$$
at the values
$$\lambda_z = \sage{lambda_za},\quad s_k = \sage{s_ka},$$
step by step:
$$\tension(\lambda_z,s_k) = \sagestr{ss} = \sagestr{sss} = \sage{tension(lambda_za,s_ka)}.$$

\end{document}

more