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

 Réponse acceptée

Mischa Kim
Mischa Kim le 31 Mar 2014
Modifié(e) : Mischa Kim le 31 Mar 2014
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 commentaire

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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by