在 tikz 上绘制非初等函数的逆函数

在 tikz 上绘制非初等函数的逆函数

在研究一个物理问题(某个版本的单摆)时,我能够求解运动方程并得到以下结果:

在此处输入图片描述

我想在 tikz 上绘制 theta(t)(当然,对于长度 l 的固定值和最大角度 theta_max),最好不必在单独的程序上生成值列表。积分对于 theta=theta_max 是不恰当的,这可能会带来额外的困难。我还想知道是否有一种简单的方法可以用 animate 包来为这个钟摆制作动画(如果我有明确的表达式,我知道如何为角度为 theta(t) 的钟摆制作动画,但在这种情况下不知道)。有什么帮助吗?

答案1

在这种情况下,它看起来Asymptote是一个更合适的工具,因为它有一个内置函数

real simpson(real f(real), real a, real b, real acc=realEpsilon, real dxmax=b-a)

它使用自适应辛普森积分返回f从 到a的积分。b

// inv-int-graph.asy
//
// run 
//    asy inv-int-graph.asy
// to get a standalone inv-int-graph.pdf
//
settings.tex="pdflatex";
import graph;
import math;

real pagew=9cm,pageh=0.618*pagew;
size(pagew,pageh,IgnoreAspect);

import fontsize;defaultpen(fontsize(7.5pt));
texpreamble("\usepackage{lmodern}"+"\usepackage{amsmath}"
+"\usepackage{amsfonts}"+"\usepackage{amssymb}");

pen linePen=darkblue+  0.7bp;

real scx=0.5, scy=0.05;
int xCells=19, yCells=13;
add(shift(-2*scx,-2*scy)*scale(scx,scy)*grid(xCells,yCells,paleblue+0.2bp));
real xmin=0,xmax=8.5;
real ymin=0,ymax=0.53;
xaxis("$t$",xmin,xmax,RightTicks(Step=1,step=0.5),above=true);
yaxis("$\theta$",ymin,ymax,LeftTicks (Step=0.1,step=0.05),above=true);

typedef pair pairFreal(real);

// Assuming that `g` is the acceleration due to gravity
// with the default value `9.8 m/s^2`.

pairFreal F(real L, real theta_max, real g=9.8){
  real f(real theta){return L/(1-exp(g*(theta^2-theta_max^2)))^(1/2);};
  return new pair(real phi){return (simpson(f,0,phi), phi);};
}

real L,theta_min,theta_max;
L=12; 
theta_max=pi/6;
theta_min=0;
real eps=1e-8;

guide gf=graph(F(L,theta_max),theta_min,theta_max-eps,n=100,operator..);
draw(gf,linePen);
label("$\theta(t)$",relpoint(gf,0.5),plain.NW);

在此处输入图片描述

答案2

\pstODEsolve积分形式的函数可以重写为微分形式,并使用PSTricks 包中的 (RKF45)作为初值问题求解pst-ode

\documentclass[pstricks,border=1cm,12pt]{standalone}

\usepackage{pst-ode,pst-plot}
\usepackage{xfp}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function integral
% #1: theta (input)
% #2: PS variable for result list (output)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\F(#1)#2{%     two output points are enough---v   v---y[0](0) (initial value)
  \pstODEsolve[algebraicAll]{retVal}{y[0]}{0}{#1}{2}{0.0}{\L/sqrt(1-Euler^(\g*(t^2-\thetaMax^2)))}
  %         integration interval theta=0---^   ^---"theta"
  %
  %  initialise empty solution list given as arg #2, if necessary
  \pstVerb{/#2 where {pop}{/#2 {} def} ifelse}
  %  From `retVal', we throw away y(theta=0), and append `y(theta) theta' to our
  %  solution list (arg #2):
  \pstVerb{/#2 [#2 retVal exch pop #1] cvx def}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\def\L{12}
\edef\thetaMax{\fpeval{pi/6}}
\def\g{9.8}

% solve function integral for a number of plotpoints
\multido{\rTheta=0.0+\fpeval{\thetaMax/100}}{101}{
  \F(\rTheta){thetaOverTime} %results appended to solution list `thetaOverTime'
}

%plot result
\begin{psgraph}[xAxisLabel=$t$,yAxisLabel=$\theta$,ticksize=6pt,
  Dx=1,Dy=0.1](0,0)(8.5,0.55){0.8\linewidth}{0.45\linewidth}
  \listplot{thetaOverTime}
\end{psgraph}

\end{document}

在此处输入图片描述

相关内容