MATLAB: Substituting solutions in system of differential equations

MATLABsubstitutionssystem of differential equations

I have a system of three differential equations. In this case, it is a simple enough idea to solve the first for x1…sub value for x1 into second equation, solve for x2 and sub it into the third equation.
This was working out fine until I reached the final substitution. If it hadn't worked from the start then I probably wouldn't be as puzzled.
Alpha, beta, and delta are to remain undefined in this context, and simply carried through in each equation.
Dx1 = p – x1*alpha
Dx2 = x1*alpha – x2*beta
Dx3 = x2*beta – x3*delta
x1(0)=0, x2(0)=0, x3(0)=0
I can't imagine that the introduction of "delta" is my problem. Have I asked too much of "dsolve"?
Thank you for any advice you have. I'll keep checking into the errors, but they haven't shed any light on the situation for me yet.
>> soln1 = dsolve('Dx1 = p - x1*alpha','x1(0) = 0', ' t ' )
soln1 =
(p - p/exp(alpha*t))/alpha
>> soln2 = dsolve('Dx2 = soln1*alpha - x2*beta','x2(0) = 0', ' t ' )
soln2 =
(alpha*soln1 - (alpha*soln1)/exp(t*beta))/beta
>> soln3 = dsolve('Dx3 = soln2*beta - x3*delta','x3(0) = 0', ' t ' )
??? Error using ==> mupadmex
Error in MuPAD command: Illegal variable context [DOM_VAR];
during evaluation of 'solvelib::indets'
Error in ==> sym.sym>sym.mupadmexnout at 2003
out = mupadmex(fcn,args{:});
Error in ==> dsolve>mupadDsolve at 190
[var_list,R] = mupadmexnout('mllib::dsolve',sys,x,ignoreConstraints);
Error in ==> dsolve at 97
[R,vars] = mupadDsolve(ignoreConstraints,varargin{1:narg});

Best Answer

When you use quoted string expressions for dsolve or sym then you are using MuPAD expressions rather than symbolic expressions . In MuPAD beta is a function (the beta function ) and that is interfering with what you want to do.
You should rewrite to use symbolic expressions .
It does get a bit tricky to represent boundary conditions of derivatives before R2011b without sym() . You might also need to convert the equality A=B to A-B .
note that your computation does not do what you think it does . If you assign to a variable and then mention the name of the variable in a quoted string that you sym or dsolve then there is no connection between the two names unless you subs() to replace the character name with the associated value. This is not an issue if you do not use character vectors of symbolic expressions .