Dynamic changing values

Hello, I have a question about dynamic changing values.
A list of values (or maybe vectors or maybe matrices): a, b, c, d, e, f, ... ...
There are equations between a, b, c, and d, e, f
---------------
*a* , b, c,
---------------
*d*, e, f ....
---------------
a = x1*b + x2 * c
d = x1*e + x2 * f
values *a* depends on value b and c
values *d* depends on value e and f
x1, x2 are two constant,
And b, c, e, f are variables, their values keep updating in a loop. How to update a, d's values dynamically once b, c, e, f are changed?
I see matlab has no pointer like C, C++. Can matlab do changing values dynamically?
Thanks in advance for your help!

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 8일

0 개 추천

If you have access to the symbolic toolbox, then you can define your values symbolically, and then when you need a particular numeric value, subs() the current values of the independent variables and double() the result of subs() to get the double precision representation of the resulting symbolic number.

댓글 수: 9

REN
REN 2011년 3월 8일
hello Walter, I have symbolic Math toolbox, unsure that's what you mean, I am not familiar with subs(),
read help subs
any documents, code example to read about this?
Walter Roberson
Walter Roberson 2011년 3월 8일
syms B C E F
a = x1*B + x2 * C;
d = x1*E + x2 * F;
Then as you change the value of the variables,
current_a = double(subs(a, {B,C,E,F}, {b,c,e,f}));
current_d = double(subs(d, {B,C,E,F}, {b,c,e,f}));
REN
REN 2011년 3월 8일
thank a lot Walter.
R = subs(S, old, new) is what I am looking for
Jiro Doke
Jiro Doke 2011년 3월 8일
Just curious, in your comment to my answer, you mentioned there too many variables like a and d. This applies to the symbolic solution as well. You need
a_new = subs(a, old, new);
d_new = subs(d, old, new);
...
for each variable. It is just as "tedious".
Walter Roberson
Walter Roberson 2011년 3월 8일
Jiro, they don't have to be done one at a time: as in the example I gave, you can do them simultaneously.
Jiro Doke
Jiro Doke 2011년 3월 8일
Walter, I'm not seeing that in your example (I assume you're talking about your second comment to this answer). You have
current_a = double(subs(a, {B,C,E,F}, {b,c,e,f}));
current_d = double(subs(d, {B,C,E,F}, {b,c,e,f}));
One for "a" and one for "d". I was just stating that this is essentially the same amount of "tediousness" as doing it numerically. I don't think you can do this:
[a_new, d_new] = subs({a, d}, {B,C,E,F}, {b,c,e,f})
Walter Roberson
Walter Roberson 2011년 3월 8일
True. Though if the symbolic equations were all in an array or vector,then subs() could operate over the array or vector simultaneously. If need be you could then mat2cell(), assign that to a variable, and then
[a_new,d_new,...] = deal(t{:});
Walter Roberson
Walter Roberson 2011년 3월 8일
num2cell(), not mat2cell().
REN
REN 2011년 3월 9일
Yes, thanks again Jiro and Walter for your good idea . I do use mat2cell()(because thess variables are from large matrix) then deal(t{:}) as you suggest.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jiro Doke
Jiro Doke 2011년 3월 8일

0 개 추천

Just redefine a and d after you update the other values:
for id = 1:100
a = x1*b + x2 * c
d = x1*e + x2 * f
...
<do your stuff>
...
<update b, c, e, f>
end

댓글 수: 3

REN
REN 2011년 3월 8일
This isn't going to work..I try to update a list of values, a lot
these values dynamically linked with other variables.
Jiro Doke
Jiro Doke 2011년 3월 8일
Well, I guess I don't fully understand your question. In my above example, every time through the loop, a and d are updated with the new set of values for b, c, e, f. Can you explain why this doesn't work?
REN
REN 2011년 3월 8일
In my case, there are too many variables like a, d.
Writing a long list of varibles in for loop is a bit tedious. Thanks your help anyway...

댓글을 달려면 로그인하십시오.

Daniel Shub
Daniel Shub 2011년 3월 8일

0 개 추천

Seems like this might be related to the polynomial class example included in the OOP guide
web([docroot '/techdoc/matlab_oop/f3-39071.html'])

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by