필터 지우기
필터 지우기

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 CenterFile Exchange에서 Conversion 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