
我正在嘗試自動化報告,以允許我更改頂部定義的變量,這些變數將級聯到具有更新數字的文件中。
我的問題是嘗試計算反三角函數,其中函數的參數實際上是另一個方程式(請參閱螢幕截圖)。 (我認為 \def 只是一個字串,當放入 tikz 時,會對其進行求值。)
有人可以幫助我嗎:
- 將方程式(參數)計算為另一個變數以解析為單一數字,或者
- 描述如何正確地將方程式嵌入到反三角函數中,或者
- 幫忙用別的方法嗎?
您將在下面的 MWE 中看到我想使用計算器套件中的 \ARCSIN 。有沒有更好的可以使用?
謝謝
\documentclass{article}
\usepackage{calc}
\usepackage{calculator}
\usepackage{trig}
\begin{document}
%% Defined Variables
\def\CrankAngle{170} % Angle position of the crank for piston dynamics
\def\Stroke{60} % Piston stroke, which is equivalent to crank working diameter
\def\ConRodLength{100} % Length of connecting rod
\def\PistonOffset{25} % L_o - offset of the piston cylinder from the crank centerline
%% Derived Variables (Calculated from Defined Variables)
\CalculateCos{\CrankAngle} % Need to pre-calculate the value before using
\def\StrokeXPos{\UseCos{\CrankAngle}*\Stroke/2} % Assign the value of the recently-calculated sin to a global variable MUST DO
\CalculateSin{\CrankAngle} % Need to pre-calculate the value before using
\def\StrokeYPos{\UseSin{\CrankAngle}*\Stroke/2} % Assign the value of the recently-calculated sin to a global variable MUST DO
\def\ConRodYOffset{\PistonOffset -\StrokeYPos}
\def\ConRodSinRatio{\ConRodYOffset/\ConRodLength}
%\ARCSIN{\ConRodSinRatio}{\sol} - WHAT TO USE THIS (OR SIMILAR) BUT NEED NUMBER IN RATIO; NOT EXPRESSION
\section{Sample Evaluations}
X-Position = \StrokeXPos
Y-Position = \StrokeYPos
Con Rod Y-Offset = \ConRodYOffset
Con Rod Sin Ratio = \ConRodSinRatio
\end{document}
答案1
我一直用於pgf
計算並且似乎效果很好:
代碼:
\documentclass{article}
\usepackage{mathtools}% For {align*}
\usepackage{pgf}
\begin{document}
%% Defined Variables
\def\CrankAngle{170} % Angle position of the crank for piston dynamics
\def\Stroke{60} % Piston stroke, which is equivalent to crank working diameter
\def\ConRodLength{100} % Length of connecting rod
\def\PistonOffset{25} % L_o - offset of the piston cylinder from the crank centerline
%% Derived Variables (Calculated from Defined Variables)
\pgfmathsetmacro\StrokeXPos{cos(\CrankAngle)*\Stroke/2} % Assign the value of the recently-calculated sin to a global variable MUST DO
\pgfmathsetmacro\StrokeYPos{sin(\CrankAngle)*\Stroke/2} % Assign the value of the recently-calculated sin to a global variable MUST DO
\pgfmathsetmacro\ConRodYOffset{\PistonOffset -\StrokeYPos}
\pgfmathsetmacro\ConRodSinRatio{\ConRodYOffset/\ConRodLength}
\pgfmathsetmacro\ArcSinValue{asin(\ConRodSinRatio)}
\section{Sample Evaluations}
\begin{align*}
\text{X-Position} &= \StrokeXPos \\
\text{Y-Position} &= \StrokeYPos \\
\text{Con Rod Y-Offset} &= \ConRodYOffset \\
\text{Con Rod Sin Ratio} &= \ConRodSinRatio \\
\text{Arc Sin Value} &= \ArcSinValue \\
\end{align*}
\end{document}