
我想在複平面上繪製任何給定多項式的根。
範例:給定 $P(x)=x^4-x^3-1$。我想在 $Oxy$ 複平面上繪製該多項式的所有四個根。
我想 Tikz 在這種情況下可能是有用的工具,但我沒有這個包的經驗。
答案1
當您轉向更技術性的數學時,您應該使用該sagetex
軟體包,因為它使您可以存取名為的開源 CAS智者。 CTAN 的文檔是這裡。這是獲得你想要的東西的“快速而骯髒”的方法。
\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
x = polygen(QQ)
f = x^4-x^3-1
root_list = f.roots(CC)
real_roots = []
for root in root_list:
real_roots += [root[0].n(digits=3)]
P = list_plot(real_roots,color='red',size=25)
\end{sagesilent}
The roots of the polynomial $\sage{f}$ plotted in the complex plane
\begin{center}
\sageplot[scale=.8]{P}
\end{center}
The roots of $\sage{f}$ are $\sage{real_roots}$.
\end{document}
這是輸出:
我不知道程式碼的複雜性,我只是透過參考將一些程式碼拼湊在一起這和這找出代碼。我認為
x = polygen(QQ)
會讓你找到具有有理係數的多項式的根,並f.roots(CC)
告訴聖人找到任何複雜的根。由於 SAGE 是 CAS,這些數字可以是 sqrt(2) 等對象,我們希望將它們強制轉換為可以繪製的小數。這是透過 實現的for root in root_list: real_roots += [root[0].n(digits=3)]
。實際的繪圖儲存在變數 P 中,其中P = list_plot(real_roots,color='red',size=25)
顏色和大小指的是最初太小而不易看到的點。這一切都是在sagesilent
模式下完成的,這就像不進入文件的廢紙。在 LaTeX 程式碼中,用於\sage{}
取得數字/計算並\sageplot{}
取得在 SAGE 中完成的繪圖。透過 Sage 進行繪圖有助於縮短程式碼,並且由於 CAS 正在執行數學運算,因此您可以更改函數(只需記住您需要係數和變數之間的乘法),SAGE 將計算出結果。您可以透過更多編碼使情節看起來更漂亮tikz
,你可以參考我如何為 Zeta 函數做這件事這裡。這將需要相當多的額外行。請注意,在我的程式碼中,SAGE 還能夠透過 為您提供 4 個零\sage{real_roots}
。讓 CAS 來做這項工作可以防止錯誤。
SAGE 不是 LaTeX 發行版的一部分;訪問它的最佳方式是透過免費的 Cocalc 帳戶,點擊這裡。
答案2
鈦kZ 不是電腦代數系統。當然,您可以自己計算根並使用極坐標繪製它們。 (原則上你甚至可以讓 TikZ 解以數值方式決定根的方程,但這可能有點瘋狂。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\DeclareMathOperator{\re}{Re}
\DeclareMathOperator{\im}{Im}
\begin{document}
\begin{tikzpicture}[scale=4]
\draw[-latex] (-1.5,0) -- (1.75,0) node[below left] {$\re z$};
\draw[-latex] (0,-1.5) -- (0,1.5) node[below right] {$\im z$};
\draw (1,0.05) -- (1,-0.05) node[below]{1};
\draw (0.05,1) -- (-0.05,1) node[left]{i};
\foreach \X/\Y in {-76.5/0.94,76.5/0.94,180/0.82,0/1.38}
{\fill (\X:\Y) circle[radius=1pt];}
\end{tikzpicture}
\end{document}
答案3
下次,您應該發布一個最小的工作範例,以吸引更多用戶造訪您的貼文。無論如何,您是新用戶,所以這個答案是歡迎您來到 TeX.SE!
首先,我不認為它有兩個以上的實根。
你可以用 Ti 很容易地繪製它kZ:
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[>=stealth,scale=2]
\draw[->] (0,-2.5)--(0,2.5) node[left] {$y$};
\draw[->,name path=ox] (-2.5,0)--(2.5,0) node[above]{$x$};
\draw (0,0) node[below left] {$O$};
\foreach \i in {-2,-1,1,2} {
\draw (-.05,\i)--(.05,\i);
\draw (0,\i) node[left] {$\i$};
\draw (\i,-.05)--(\i,.05);
\draw (\i,0) node[below] {$\i$};
}
\draw[red,name path=pl] plot[smooth,samples=500,domain=-1.1:1.6] (\x,{\x*\x*\x*\x-\x*\x*\x-1});
\path[name intersections={of=ox and pl,by={i1,i2}}];
\fill (i1) circle (1pt) node[above right] {$A$};
\fill (i2) circle (1pt) node[below right] {$B$};
\end{tikzpicture}
\end{document}
現在,當你有了交點時,你就可以獲得它們的座標:
\documentclass[tikz]{standalone}
\usetikzlibrary{intersections}
\newdimen\xa
\newdimen\xb
\newdimen\ya
\newdimen\yb
\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother
% https://tex.stackexchange.com/a/239496/156344
\begin{document}
\begin{tikzpicture}[>=stealth,scale=2]
\draw[->] (0,-2.5)--(0,2.5) node[left] {$y$};
\draw[->,name path=ox] (-2.5,0)--(2.5,0) node[above]{$x$};
\draw (0,0) node[below left] {$O$};
\foreach \i in {-2,-1,1,2} {
\draw (-.05,\i)--(.05,\i);
\draw (0,\i) node[left] {$\i$};
\draw (\i,-.05)--(\i,.05);
\draw (\i,0) node[below] {$\i$};
}
\draw[red,name path=pl] plot[smooth,samples=500,domain=-1.1:1.6] (\x,{\x*\x*\x*\x-\x*\x*\x-1});
\path[name intersections={of=ox and pl,by={i1,i2}}];
\fill (i1) circle (1pt) node[above right] {$A$};
\path (i1); \pgfgetlastxy{\xa}{\ya}
\fill (i2) circle (1pt) node[below right] {$B$};
\path (i2); \pgfgetlastxy{\xb}{\yb}
\draw (0,-3) node[text width=10cm,align=left] {%
There are two roots:\\
$A$ at $({\convertto{cm}{\xa}*2}, 0)$ and $B$ at $({\convertto{cm}{\xb}*2}, 0)$.};
\end{tikzpicture}
\end{document}
當然,您可以隨時\xa
在\xb
任何您想要的地方使用;-)
正如土撥鼠所說,TikZ 不是計算機。它只能幫助我們使用交集來找到真正的根。我認為除了自己尋找根源之外,使用任何 LaTeX 工具都不容易做到這一點。