Now I assumed that you want the code to be fairly general, so I did this to be able to work with any given number of equations and any given number of variables, and I did not do any calculations manually.
Please note that the way the symbolic Toolbox works varies from year to year, but hopefully this works for you. Now you can add the Eq1 equation to Eq1 's input dSolve , but there are two problems with this: one of them is that dSolve seems to prefer character input, and the second is that dSolve doesn't seem to have 3 independent variables a , b and c (he sees only 2 variables, b and c ).
To solve the second problem, I differentiated the original equation to obtain a new differential equation, there were three problems with this: the first one Matlab calculated the derivative of a with respect to t as 0 , so I had to replace a with a(t) and such as for b and c (I called a(t) long version of a ). The second problem was that Matlab used inconsistent notation instead of representing the derivative of a as Da , it represented it as diff(a(t), t) , so I had to replace the latter with the previous one and the same as for b and c ; this gave me Da = Db + Dc . The last problem is that the system is now defined, so I needed to get the initial values, here I could solve for a(0) , but Matlab seemed happy with using a(0) = b(0) + c(0) .
Now, back to the original first problem, to solve that I had to convert all characters back to char.
Here is the code
function SolveExample syms abcy C1 C2 t; Eq1 = sym('a = b + c'); dEq1 = 'Db = 1/C1*y(t)'; dEq2 = 'Dc = 1/C2*y(t)'; [dEq3, initEq3] = ... TurnEqIntoDEq(Eq1, [abc], t, 0); % In the most general case Eq1 will be an array % and thus DEq3 will be one too dEq3_char = SymArray2CharCell(dEq3); initEq3_char = SymArray2CharCell(initEq3); % Below is the same as % dsolve(dEq1, dEq2, 'Da = Db + Dc', ... % 'b(0)=0','c(0)=0', 'a(0) = b(0) + c(0)', 't'); [sol_dEq1, sol_dEq2, sol_dEq3] = dsolve(... dEq1, dEq2, dEq3_char{:}, ... 'b(0)=0','c(0)=0', initEq3_char{:}, 't') end function [D_Eq, initEq] = ... TurnEqIntoDEq(eq, depVars, indepVar, initialVal) % Note that eq and depVars % may all be vectors or scalars % and they need not be the same size. % eq = equations % depVars = dependent variables % indepVar = independent variable % initialVal = initial value of indepVar depVarsLong = sym(zeros(size(depVars))); for k = 1:numel(depVars) % Make the variables functions % eg. a becomes a(t) % This is so that diff(a, t) does not become 0 depVarsLong(k) = sym([char(depVars(k)) '(' ... char(indepVar) ')']); end % Next make the equation in terms of these functions eqLong = subs(eq, depVars, depVarsLong); % Now find the ODE corresponding to the equation D_EqLong = diff(eqLong, indepVar); % Now replace all the long terms like 'diff(a(t), t)' % with short terms like 'Da' % otherwise dSolve will not work. % First make the short variables 'Da' D_depVarsShort = sym(zeros(size(depVars))); for k = 1:numel(depVars) D_depVarsShort(k) = sym(['D' char(depVars(k))]); end % Next make the long names like 'diff(a(t), t)' D_depVarsLong = diff(depVarsLong, indepVar); % Finally replace D_Eq = subs(D_EqLong, D_depVarsLong, D_depVarsShort); % Finally determine the equation % governing the initial values initEq = subs(eqLong, indepVar, initialVal); end function cc = SymArray2CharCell(sa) cc = cell(size(sa)); for k = 1:numel(sa) cc{k} = char(sa(k)); end end
Some minor notes, I changed == to = , as this seems to be the difference between our versions of Matlab. I also added t as an independent variable in dSolve . I also suggested that you know about cells, numerical, linear indices, etc.