Creating a symbolic array

3 次查看(过去 30 天)
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')

更多回答(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