フィルターのクリア

How can i input value in symbolic expression, automatically?

21 ビュー (過去 30 日間)
연승 김
연승 김 2021 年 3 月 25 日
コメント済み: 연승 김 2021 年 3 月 25 日
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.
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??

採用された回答

Walter Roberson
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.
  1 件のコメント
연승 김
연승 김 2021 年 3 月 25 日
Thank you for your kind and quick reply!!
I know and studied about the 'subs' function, but I cannot think of applying..
It means I'm novice...beginner.
Thank you again for your answer!! Have a nice day!

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

その他の回答 (0 件)

カテゴリ

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