The following error occurred converting from sym to double: Unable to convert expression into double array.

2 ビュー (過去 30 日間)
Hello,
When I run my script, I get an error saying "The following error occurred converting from sym to double:
Unable to convert expression into double array." I tried converting the symbolic variable using double (x) but I still get another error. I am trying to create a vector with the variable x.
syms x
for j = 2:n
X_T(1,j) = x ^(j-1) ;
end
  1 件のコメント
Shashank Gupta
Shashank Gupta 2021 年 1 月 18 日
I ran the exact same code which you described above assuming "n" some random number and I haven't gotten any such error which you mentioned. But looking at the error it does seems like problem is somewhere in converting symbolic variable to double. Check out subs function. Might help you.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 1 月 18 日
You initialized X_T to numeric (such as double precision), either explicitly or else that you happened to have a numeric one sitting around in your workspace. However, the symbolic x in the results cannot be converted to be stored in a double precision location.
Either do not initialize X_T or else use
X_T = zeros(1, n, 'sym');

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by