Creating a symbolic array

조회 수: 3 (최근 30일)
Aleem Andrew
Aleem Andrew 2020년 11월 24일
댓글: Aleem Andrew 2020년 11월 25일
When I tried to create an array consisting of expressions in terms of a symbolic variable I get the error message
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
But I don't want to evaluate the expressions at a particular value. Instead I want expressions in terms of the symbolic variable q. Does anyone have suggestions regarding how this can be done?
syms q
a = [];
for i = 1:5
for j = 1:5
a(i,j) =q;
end
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 25일
a = sym([]);
or better yet
a = zeros(5,5,'sym')
  댓글 수: 1
Aleem Andrew
Aleem Andrew 2020년 11월 25일
Thanks for your answer

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Stephan
Stephan 2020년 11월 24일
편집: Stephan 2020년 11월 24일
>> q = sym('q', [5, 5])
q =
[ q1_1, q1_2, q1_3, q1_4, q1_5]
[ q2_1, q2_2, q2_3, q2_4, q2_5]
[ q3_1, q3_2, q3_3, q3_4, q3_5]
[ q4_1, q4_2, q4_3, q4_4, q4_5]
[ q5_1, q5_2, q5_3, q5_4, q5_5]
>> whos q
Name Size Bytes Class Attributes
q 5x5 8 sym
>> q(1,1:end) = 42
q =
[ 42, 42, 42, 42, 42]
[ q2_1, q2_2, q2_3, q2_4, q2_5]
[ q3_1, q3_2, q3_3, 42, q3_5]
[ q4_1, q4_2, q4_3, q4_4, q4_5]
[ q5_1, q5_2, q5_3, q5_4, q5_5]

Steven Lord
Steven Lord 2020년 11월 25일
If you want an array of q's:
syms q
A = repmat(q, [5 5])
A = 

카테고리

Help CenterFile Exchange에서 Symbolic Variables, Expressions, Functions, and Preferences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by