How can i input value in symbolic expression, automatically?
21 ビュー (過去 30 日間)
古いコメントを表示
Hi. I'm not good at MATLAB. so it's hard to me...
I make symbolic expression, bou I have some trouble.
syms a [1 2]
syms 'a_x%d' [2 3]
When I code like above, I can get like below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/561868/image.png)
And I input values to symbolic expression, it is not work that I wanted.
for i = 1:2
for j = 1:3
a_x(i,j) = i+j
end
a(i) = i
end
Then, the result is below.
a_x =
[2, 3, 4]
[3, 4, 5]
a =
[1, 2]
But I want likt this like below, automatically.
a_x11 = a_x(1,1)
a_x12 = a_x(1,2)
a_x13 = a_x(1,3)....
a1 = a(1)
a2 = a(2)
How can I do it??
0 件のコメント
採用された回答
Walter Roberson
2021 年 3 月 25 日
We recommend against that.
In the specific case of symbolic work, code
for i = 1:2
for j = 1:3
a_x_val(i,j) = i+j;
end
a_val(i) = i;
end
and continue to compute with a_x and a symbolic in your code. When you get to the point where the code needs a specific value for the variables,
subs(expression, [a; a_x(:)], [a_val; a_x_val(:)])
Putting all the variables together like [a; a_x(:)] is needed in order to get proper simultaneous substitution.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!