Solve system of equations when symbolic vector is referencing its own elements?

I have a script that prints out a symbolic vector "a" in terms of its elements a(1),...,a(n):
a =
2610.0 - 0.0001*a5 - 1.0e-6*a7 - 0.01*a3
- 0.02*a4 - 0.0003*a6 - 3027.0
1176.0 - 0.0007*a7 - 0.03333*a5
266.1 - 0.05*a6
- 0.07*a7 - 322.0
64.24
-1.701
"a" is a system of equations where the elements of "a" reference other elements of "a", e.g. a(2) references a(4) and a(6):
a(2) = - 0.02*a4 - 0.0003*a6 - 3027.0
I want to write a(1),a(2),...,a(n) without any symbols appearing on the right-hand side. In other words, I want to substitute numerical values into the elements of "a".
I've tried solve(), vpasolve(), and subs() but I can't format the output to replace the symbols inside each element.
What am I doing wrong?
Thanks,
Michael

 採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 31 日
編集済み: Mischa Kim 2014 年 3 月 31 日
Michael, use
syms a1 a2 a3 a4 a5 a6 a7
a = [a1 a2 a3 a4 a5 a6 a7]';
eq = [ 2610.0 - 0.0001*a5 - 1.0e-6*a7 - 0.01*a3,
-0.02*a4 - 0.0003*a6 - 3027.0,
1176.0 - 0.0007*a7 - 0.03333*a5,
266.1 - 0.05*a6,
-0.07*a7 - 322.0,
64.24,
-1.701];
sol = vpasolve(eq==a);

1 件のコメント

Michael
Michael 2014 年 3 月 31 日
編集済み: Michael 2014 年 3 月 31 日
Excellent method, thank you!
Good catch, I totally overlooked defining a new vector such as "eq". I also found that a couple "for" loops do the trick as well:
for ii = 1:nMax
for jj = 1:nMax
eq(jj) = subs(eq(jj),a(ii),eq(ii));
end
end
But your method is much cleaner.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

質問済み:

2014 年 3 月 31 日

編集済み:

2014 年 3 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by