
나는 매크로를 사용하고 있습니다여기(덕분에슈뢰딩거의 고양이). 내 MWE를 확인하세요:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{fpu}
\newcommand\pgfmathparseFPU[1]{
\begingroup
\pgfkeys{
/pgf/fpu,
/pgf/fpu/output format = fixed
}
\pgfmathparse{#1}
\pgfmathsmuggle
\pgfmathresult
\endgroup}
\begin{document}
%data values:
\def\UABmValues{{14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1}}
%prints the result to the console:
\foreach[count = \i from 0] \k in {30, 35, ..., 80}
{
\pgfmathsetmacro{\UABmValues}{\UABmValues[\i]}
\pgfmathparseFPU{-25500 / (\UABmValues / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * \k}\i, \pgfmathresult\\
}
\end{document}
다음을 제공합니다:
- 4.414001000000000
- 3.483002000000000
- 3.652002000000000
- 2.221002000000000
- 0.990002
- 0.159003
- -0.571997
- -1.302997000000000
- -1.033997000000000
- -0.064996
- 1.304004000000000
MATLAB을 사용하여 동일한 작업을 수행하면 다음과 같습니다.
UABmValues = [14.9 15.8 17.7 18.3 19 20 21.1 22.2 24.3 26.9 30.1];
R = 30 : 5 : 80;
%prints the result to the console:
for j = 1 : 11
result = -25500 / (UABmValues(j) / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * R(j);
fprintf('j=%d, ', j)
fprintf('%d.\n', result)
end
내가 다음을 얻는 것보다 :
- 4.261621e+00.
- 3.290914e+00.
- 3.388431e+00.
- 2.098301e+00.
- 9.151911e-01.
- 5.300458e-02.
- -7.017887e-01.
- -1.456052e+00.
- -1.139024e+00.
- -2.840543e-01.
- 1.217927e+00.
그 차이는 엄청납니다.
왜 그래야만하지? fpu
적어도 가능하다면 로 문제를 해결하는 방법에 대한 제안이 있으십니까 ?
미리 여러분의 도움과 노력에 감사드립니다!
답변1
PGF 부동 소수점 모듈~이다TeX 산술을 사용하므로 정확하지 않으므로 십진수 5자리를 넘지 않습니다. 이는 다목적 부동 소수점 산술 도구가 아니라 단지 조판을 수행하기 위한 것입니다.
사용 xfp
.
\documentclass{article}
\usepackage{tikz}
\usepackage{xfp}
\begin{document}
%data values:
\def\UABmValues{{14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1}}
%prints the result to the console:
\foreach[count = \i from 0] \k in {30, 35, ..., 80}
{
\pgfmathsetmacro{\UABmValues}{\UABmValues[\i]}
\i, $\fpeval{-25500 / (\UABmValues / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * \k}$\par
}
\end{document}
답변2
당신은 시도 할 수 있습니다fp,xfp(egreg의 답변 참조) 또는루아
1)업데이트 : 루아 버전
% !TEX TS-program = lualatex
\documentclass{scrartcl}
\usepackage{pgffor,pgfmath}
\def\luafun#1#2{
\directlua{
x = #1;
y = #2;
r=-25500/(x/1000-255/52)-5200-3.0897/8*y
tex.print(r)}
}
\begin{document}
\def\UABmValues{{14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1}}
\foreach[count = \i from 0] \k in {30, 35, ..., 80}
{
\pgfmathsetmacro{\myval}{\UABmValues[\i]}%
\luafun{\myval}{\k}\par
}
\end{document}
2) fp가 있는 이전 버전
\documentclass{scrartcl}
\usepackage{tikz,fp}
\newcommand\pgfmathparseFP[1]{
\begingroup
\FPeval\pgfmathresult{(#1)}
\pgfmathsmuggle
\pgfmathresult
\endgroup
}
\begin{document}
%data values:
\def\UABmValues{{14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1}}
%prints the result to the console:
\foreach[count = \i from 0] \k in {30, 35, ..., 80}
{
\pgfmathsetmacro{\myval}{\UABmValues[\i]}%
\pgfmathparseFP{-25500/(\myval/1000-255/52)-5200-3.0897/8*\k}\i, \pgfmathresult\par
}
\end{document}
답변3
CAS를 사용한 구현세이지(수학)그리고SageTeX:
나는 사용한다아라라: sagetex컴파일을 위해.
% arara: pdflatex
% arara: sagetex
% arara: pdflatex
\documentclass{scrartcl}
\usepackage{sagetex, amsmath}
\usepackage{tikz}
\usetikzlibrary{fpu}
\newcommand\pgfmathparseFPU[1]{
\begingroup
\pgfkeys{
/pgf/fpu,
/pgf/fpu/output format = fixed
}
\pgfmathparse{#1}
\pgfmathsmuggle
\pgfmathresult
\endgroup}
\begin{document}
%data values:
\def\UABmValues{{14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1}}
\section{pgfmath}
\foreach[count = \i from 0] \k in {30, 35, ..., 80}
{
\pgfmathsetmacro{\UABmValues}{\UABmValues[\i]}
\pgfmathparseFPU{-25500 / (\UABmValues / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * \k}\noindent\i, \UABmValues, \pgfmathresult \\
}
\section{SageTeX}
\subsection{Sage-Output}
$\sagestr{MyOut}$
\subsection{From sageblock or sagesilent}
\begin{sageblock}
Val = ([14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1])
## Test:
#print Val[1]
#print len(Val)
# Function
f(x,y) = -25500/(x/1000 - 255/52) -5200 -3.0897/8 *(30+5*y)
# Short Output
#for i in range (len(Val)): print i,',',float(Val[i]),',', f(Val[i],i)
# Better Output
data = [(i, float(Val[i]), f(Val[i],i)) for i in range(len(Val))]
data_str = [', '.join(map(str, t)) for t in data]
data_str = '\n'.join(data_str)
MyOut = latex(data_str)
#print data_str
\end{sageblock}
\end{document}