displayFormula
説明
例
行列およびスカラーの乗算式
3 行 3 列の行列を作成します。この行列をスカラー係数 K^2
で乗算します。
syms K A A = [-1, 0, 1; 1, 2, 0; 1, 1, 0]; B = K^2*A
B =
結果に、要素単位で実行される乗算が自動的に表示されます。
displayFormula
を使用し、演算を評価せずに乗算式を表示します。式を string として入力します。string の変数 A
はその値で置き換えられます。
displayFormula("F = K^2*A")
行列とベクトルの乗算式
3 行 3 列の行列と 3 行 1 列のベクトルを作成します。行列とベクトルを乗算するシンボリック方程式を作成します。
syms A [3 3] syms v B [3 1] eqn = B == A*v
eqn =
結果は、行列とベクトルの要素の結合箇所で乗算が実行されることを示します。
displayFormula
を使用し、要素を結合せずに乗算式を表示します。式を string として入力します。
displayFormula("B == A*v")
微分方程式の表示
微分方程式を記述する string を定義します。
S = "m*diff(y,t,t) == m*g-k*y";
微分方程式と追加のテキストを結合する string 配列を作成します。テキストとともに式を表示します。
symstr = ["'The equation of motion is'"; S;"'where k is the elastic coefficient.'"]; displayFormula(symstr)
シンボリック式の表示および評価
シンボリック式を表す string S
を作成します。
S = "exp(2*pi*i)";
S
が含まれる別の string symstr
を作成します。
symstr = "1 + S + S^2 + cos(S)"
symstr = "1 + S + S^2 + cos(S)"
displayFormula
を使用し、演算を評価せずに symstr
を式として表示します。symstr
内の S
はその値で置き換えられます。
displayFormula(symstr)
string S
および symstr
をシンボリック式として評価するには、str2sym
を使用します。
S = str2sym(S)
S =
expr = str2sym(symstr)
expr =
subs
を使用して、変数 S
にその値を代入します。double
を使用して倍精度で結果を評価します。
double(subs(expr))
ans = 3.5403
2 次方程式の表示および求解
係数 a
、b
および c
をもつ 2 次式を表す string を定義します。
syms a b c k symstr = "a*x^2 + b*x + c";
a
を k
で置き換えて、2 次式を表示します。
displayFormula(symstr,a,k)
a
、b
、および c
を 2
、3
、および -1
でそれぞれ置き換えて、2 次式を再度表示します。
displayFormula(symstr,[a b c],[2 3 -1])
2 次式を解くには、str2sym
を使用して string をシンボリック式に変換します。solve
を使用して 2 次方程式の零点を求めます。
f = str2sym(symstr); sol = solve(f)
sol =
subs
を使用して、解の a
、b
、および c
を 2
、3
、および -1
とそれぞれ置き換えます。
solValues = subs(sol,[a b c],[2 3 -1])
solValues =
入力引数
symstr
— シンボリック式を表す string
文字ベクトル | string スカラー | 文字ベクトルの cell 配列 | string 配列
シンボリック式を表す string。文字ベクトル、string スカラー、文字ベクトルの cell 配列、または string 配列として指定します。
シンボリック式を表す string を string 配列として通常の (一重引用符に囲まれた) テキストと結合することもできます。例については、微分方程式の表示を参照してください。
old
— 置き換える式または変数
文字ベクトル | string スカラー | 文字ベクトルの cell 配列 | string 配列 | シンボリック変数 | シンボリック関数 | シンボリック式 | シンボリック配列
置き換える式または変数。文字ベクトル、string スカラー、文字ベクトルの cell 配列、string 配列、シンボリック変数、シンボリック関数、シンボリック式、またはシンボリック配列として指定します。
new
— 新しい値
数値 | 文字ベクトル | string スカラー | 文字ベクトルの cell 配列 | string 配列 | シンボリック数 | シンボリック変数 | シンボリック式 | シンボリック配列
新しい値。数値、文字ベクトル、string スカラー、文字ベクトルの cell 配列、string 配列、シンボリック数、シンボリック変数、シンボリック式、またはシンボリック配列として指定します。
バージョン履歴
R2019b で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)