関数の逆数の計算方法について

33 vues (au cours des 30 derniers jours)
Tsukepen
Tsukepen le 6 Août 2018
Réponse apportée : mizuki le 7 Août 2018
お世話になります。
例えば、(1/s^2)^-1というような2次式の逆数を計算したいときに、ゼロ除算を回避しながら逆数を計算する方法は、どのように行えばよろしいでしょうか。
よろしくお願いいたします。

Réponse acceptée

mizuki
mizuki le 7 Août 2018
シンボリックではなく s に数値を代入して逆数の計算をされるという前提で回答をします。 以下のように Inf (ゼロ割)が出たときにその要素を取り除くという方法ではいかがでしょうか。
>> s = -3:3
s =
-3 -2 -1 0 1 2 3
>> a = (1./s.^2)
a =
0.1111 0.2500 1.0000 Inf 1.0000 0.2500 0.1111
>> idx = ~isinf(a)
idx =
1×7 logical 配列
1 1 1 0 1 1 1
>> res = a(idx).^-1
res =
9 4 1 1 4 9

Plus de réponses (0)

Catégories

En savoir plus sur 線形代数 dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!