How can i input value in symbolic expression, automatically?

50 views (last 30 days)
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??

Accepted Answer

Walter Roberson
Walter Roberson on 25 Mar 2021
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 Comment
연승 김
연승 김 on 25 Mar 2021
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!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!