How to parametrically solve a symbolic system of arbitrary size ?

1 view (last 30 days)
Hello,
I am trying to solve a symbolic system of equations that I automatically generate based on user data. The coefficients and the size of the system can change.
Here is an example of code for a 2x2 system :
--------------------------
eps1 = 1;
eps2 = 1;
eps = [eps1;eps2];
sigma = 1;
k = ones(2,1);
h=[1;1];
Tw = sym(zeros(2, 1));
for i=1:2
Tw(i) = sym(sprintf('Tw%d', i));
end
f = -sigma*eps.*Tw.^4;
Jacf = jacobian(f,Tw);
Tw0 = [293;293];
A = subs(Jacf,Tw,Tw0);
c = subs(f,Tw,Tw0)-A*Tw0;
T = sym(ones(2, 1));
T(1) = sym('To');
T(2) = sym('Ti');
S = sym(ones(2, 1));
for i=1:2
S(i) = sym(sprintf('S%d', i));
end
G = S+h.*(T-Tw)+c+A*T;
solve(G,Tw);
-------------------------
The system is obtained through linearisation of expression f. I would like to obtain Tw as an expression depending on T and S. But when I try to solve for G == 0, the solver solves in T and Tw instead of only Tw...
If I use solve(G,Tw(1),Tw(2)) then I get the good answer, but as the system is of arbitrary size in the general case, I don't know how to adapt this expression to get an answer.
Any idea how to fix this ?
Thanks,
Tomasz

Accepted Answer

Walter Roberson
Walter Roberson on 18 Mar 2013
Twcell = num2cell(Tw);
solve(G, Twcell{:})

More Answers (0)

Categories

Find more on Symbolic Math Toolbox 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!