配列サイズによる条件式

4 views (last 30 days)
泰誠 平山
泰誠 平山 on 20 Aug 2023
Commented: 泰誠 平山 on 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)

Accepted Answer

Hernia Baby
Hernia Baby on 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 Comment
泰誠 平山
泰誠 平山 on 20 Aug 2023
実行できました!ありがとうございました。

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!