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

 Réponse acceptée

Hernia Baby
Hernia Baby le 20 Août 2023

0 votes

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 commentaire

泰誠 平山
泰誠 平山 le 20 Août 2023
実行できました!ありがとうございました。

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 演算子と基本的な演算 dans Centre d'aide et File Exchange

Produits

Version

R2023a

Community Treasure Hunt

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

Start Hunting!