7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MATLAB の数値計算の結果を LaTeX にコピペしたい!

Last updated at Posted at 2024-02-04

はじめに

行列の固有値,固有ベクトルを計算した結果を楽にコピペする方法のメモ書きです.
上記以外にも汎用性は高いです.

環境

  • MATLAB 2023a
  • symbolic math toolbox

方法

今回は小数4桁までで丸めます.

% 固有値計算
A = [1 2 3;4 5 6;7 8 9];
[V,D] = eig(A);

% コピペ用
latex_V = latex(round(vpa(sym(V)),4));
clipboard('copy', latex_V)

% 以下がクリップボードにコピーされています
% \left(\begin{array}{ccc} -0.232 & -0.7858 & 0.4082\\ -0.5253 & -0.0868 & -0.8165\\ -0.8187 & 0.6123 & 0.4082 \end{array}\right)

latex()は symbolic 変数しか扱えないので,一度 sym() をかませてから vpa() で小数値に変換しています.
そのままだと桁数が多すぎるので round() で所望の桁数に丸めて終わり.

7
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?