How can i input value in symbolic expression, automatically?
43 views (last 30 days)
Show older comments
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??
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!