我想创建基于随机数的练习工作表,对乘法和除法进行上下缩放。
例如,一旦学生了解到:5*3=15是时候将这些知识扩展到5*3000=15000并下降到0.5*0.3=0.15。
我该怎么做呢?
下面是我编写的一些用于缩放乘法运算的代码向上。但当比例扩大 1000 倍或更大时,它似乎就会崩溃。为什么?
此外,为了缩小乘法运算,整数不适用。那我该怎么办?
谢谢你的帮助!
\documentclass{article}
\usepackage{pgf}
\pgfmathsetseed{\number\pdfrandomseed}
\usepackage{pgffor}
\newcommand{\OneExercise}
{\pgfmathrandominteger{\FactorA}{1}{10}
\pgfmathdeclarerandomlist{PowerOfTen}{{1}{10}{100}{1000}}
\pgfmathrandomitem{\PowerOfTen}{PowerOfTen}
\pgfmathrandominteger{\FactorBInteger}{1}{10}
\pgfmathsetmacro{\FactorB}{int(\FactorBInteger*\PowerOfTen)}
\pgfmathsetmacro{\Product}{int(\FactorA*\FactorB)}
\(\FactorA\times\FactorB = \Product\)
}
\begin{document}
\section*{Scaled Up Times Tables}
\foreach \x in {1,2,3,...,5}
{\OneExercise }
\end{document}
答案1
pgf
有时会遇到较大的数字,我想我不知道为什么它在这里失败了。xfp
处理这类事情会更好一些,所以你可以用它来代替。
对于放大或缩小,绘制一个从 -3 到 3 的随机整数,然后按该整数的 10 次方进行缩放。
\documentclass{article}
\usepackage{pgf, xfp}
\pgfmathsetseed{\number\pdfrandomseed}
\usepackage{pgffor}
\newcommand{\OneExercise}
{\pgfmathrandominteger{\FactorA}{1}{10}
\pgfmathrandominteger{\TenPower}{-3}{3}
\pgfmathrandominteger{\FactorBInteger}{1}{10}
\def\FactorB{\fpeval{\FactorBInteger*10^{\TenPower}}}
\def\Product{\fpeval{\FactorA*\FactorB}}
\(\FactorA\times\FactorB = \Product\)
}
\begin{document}
\section*{Scaled Up Times Tables}
\foreach \x in {1,...,5}
{\OneExercise }
\end{document}
答案2
expl3
为什么一开始不用呢?
\documentclass{article}
\usepackage{xparse,xfp,pgffor}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\doseveral}{m+m}
{
\prg_replicate:nn { #1 } { #2 }
}
\NewDocumentCommand{\declarefpvar}{mo}
{
\fp_zero_new:c { l_wcla_math_var_#1_fp }
\IfValueT { #2 } { \fp_set:cn { l_wcla_math_var_#1_fp } { #2 } }
}
\NewDocumentCommand{\setfpvar}{mm}
{
\fp_set:cn { l_wcla_math_var_#1_fp } { #2 }
}
\NewDocumentCommand{\declarefpvector}{mo}
{
\seq_clear_new:c { l_wcla_math_vector_#1_seq }
\IfValueT { #2 } { \seq_set_from_clist:cn { l_wcla_math_vector_#1_seq } { #2 } }
}
\NewDocumentCommand{\setfpvector}{mm}
{
\seq_set_from_clist:cn { l_wcla_math_vector_#1_seq } { #2 }
}
\NewExpandableDocumentCommand{\randomitem}{m}
{
\seq_rand_item:c { l_wcla_math_vector_#1_seq }
}
\NewExpandableDocumentCommand{\usefpvar}{m}
{
\fp_use:c { l_wcla_math_var_#1_fp }
}
\ExplSyntaxOff
\newcommand{\OneExercise}{%
\declarefpvar{FactorA}[randint(1,10)]%
\declarefpvector{PowerOfTen}[0.001,0.01,0.1,1,10,100,1000]%
\declarefpvar{FactorB}[randint(1,10)*\randomitem{PowerOfTen}]%
\declarefpvar{Product}[\usefpvar{FactorA}*\usefpvar{FactorB}]%
\(\usefpvar{FactorA}\times\fpeval{\usefpvar{FactorB}} = \usefpvar{Product}\)
}
\begin{document}
\section*{Scaled Up Times Tables}
These are twelve exercises
\doseveral{12}{\OneExercise\par}
\end{document}