配列サイズによる条件式

3 Ansichten (letzte 30 Tage)
泰誠 平山
泰誠 平山 am 20 Aug. 2023
Kommentiert: 泰誠 平山 am 20 Aug. 2023
以下のような方程式において,解の配列サイズが4×1ならば1,それ以外ならば0とするようなコードの書き方をご教授頂きたいです。本来行いたいこととしてはforループを用いてvpasolveの中の式を入れ替え,ループ毎に解の配列サイズによってその後の処理を変えたいです。何卒宜しくお願い致します。
syms x
S = vpasolve(2*x^4 + 3*x^3 - 4*x^2 - 3*x + 2 == 0, x)

Akzeptierte Antwort

Hernia Baby
Hernia Baby am 20 Aug. 2023
sizeを使ってみてはいかがでしょうか?
syms x
S = vpasolve(2*x^4 + 3*x^3 - 4*x^2 - 3*x + 2 == 0, x)
S = 
sz = size(S,1)
sz = 4
if sz == 4
disp("解の数は4")
else
disp("解の数は4ではない")
end
解の数は4
  1 Kommentar
泰誠 平山
泰誠 平山 am 20 Aug. 2023
実行できました!ありがとうございました。

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!