Dynamic changing values

2 ビュー (過去 30 日間)
REN
REN 2011 年 3 月 8 日
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 日
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 件のコメント
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 日
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 件のコメント
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 日
Seems like this might be related to the polynomial class example included in the OOP guide
web([docroot '/techdoc/matlab_oop/f3-39071.html'])
  1 件のコメント
REN
REN 2011 年 3 月 8 日
thanks for your link too

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

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by