From: Edward D. on
Hi all,

Can you solve the following in matlab 2009b 64 bit (macosx with snow leopard)? I get the errors given below the code. It takes a lot of time before Matlab gives the error. Where do I go wrong?

%-----------------------
syms p0 p00 p1 p2 cn cr dn dr a an ar bn br T tau real;

myfun = [ -(tau*(2*an + 2*bn*cn - 4*bn*p1 - dn*tau))/2; -(tau*(2*ar + 2*br*cr - 4*br*p0 - dr*tau))/2; ((T - tau)*(T*dn - 2*an - 2*bn*cn + 4*bn*p2 + dn*tau))/2; ((T - tau)*(T*dr - 2*ar - 2*br*cr + 4*br*p00 + dr*tau))/2; an*p2 - an*p1 - ar*p0 + ar*p00 + bn*p1^2 - bn*p2^2 + br*p0^2 - br*p00^2 - bn*cn*p1 + bn*cn*p2 - br*cr*p0 + br*cr*p00 + dn*p1*tau - dn*p2*tau + dr*p0*tau - dr*p00*tau];

soln = solve(myfun,'p1','p2','p0','p00','tau');
%-----------------------

??? Error using ==> mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.

Error in ==> sym.sym>sym.subsref at 1366
B = mupadmex('mllib::subsref',A.s,inds{:});

Error in ==> solve>assignOutputs at 110
S.(char(symvars(j))) = R(:,j);

Error in ==> solve at 87
varargout = assignOutputs(nargout,R,symvars);
From: Bruce on
"Edward D." <edwardawsremove.this(a)gmail.com> wrote in message <hjdcnp$55c$1(a)fred.mathworks.com>...
> Hi all,
>
> Can you solve the following in matlab 2009b 64 bit (macosx with snow leopard)? I get the errors given below the code. It takes a lot of time before Matlab gives the error. Where do I go wrong?
>
> %-----------------------
> syms p0 p00 p1 p2 cn cr dn dr a an ar bn br T tau real;
>
> myfun = [ -(tau*(2*an + 2*bn*cn - 4*bn*p1 - dn*tau))/2; -(tau*(2*ar + 2*br*cr - 4*br*p0 - dr*tau))/2; ((T - tau)*(T*dn - 2*an - 2*bn*cn + 4*bn*p2 + dn*tau))/2; ((T - tau)*(T*dr - 2*ar - 2*br*cr + 4*br*p00 + dr*tau))/2; an*p2 - an*p1 - ar*p0 + ar*p00 + bn*p1^2 - bn*p2^2 + br*p0^2 - br*p00^2 - bn*cn*p1 + bn*cn*p2 - br*cr*p0 + br*cr*p00 + dn*p1*tau - dn*p2*tau + dr*p0*tau - dr*p00*tau];
>
> soln = solve(myfun,'p1','p2','p0','p00','tau');
> %-----------------------
>
> ??? Error using ==> mupadmex
> Error in MuPAD command: Index exceeds matrix dimensions.
>
> Error in ==> sym.sym>sym.subsref at 1366
> B = mupadmex('mllib::subsref',A.s,inds{:});
>
> Error in ==> solve>assignOutputs at 110
> S.(char(symvars(j))) = R(:,j);
>
> Error in ==> solve at 87
> varargout = assignOutputs(nargout,R,symvars);

Hello Edward,

I used Matlab r2009B to try out the problem on a 32-bit computer.
I could not get the very last bit of the matrix to work but the rest worked fine.
You just need to enclose the expressions in single quotes.

I converted the solution from a struct to a vector and then displayed the solution
as below.

clc;
syms p0 p00 p1 p2 cn cr dn dr a an ar bn br T tau real;
myfun = [ '-(tau*(2*an + 2*bn*cn - 4*bn*p1 - dn*tau))/2', ...
'-(tau*(2*ar + 2*br*cr - 4*br*p0 - dr*tau))/2', ...
'((T - tau)*(T*dn - 2*an - 2*bn*cn + 4*bn*p2 + dn*tau))/2', ...
'((T - tau)*(T*dr - 2*ar - 2*br*cr + 4*br*p00 + dr*tau))/2']; %, ...last bit is an invalid expression
%'an*p2 - an*p1 - ar*p0 + ar*p00 + bn*p1^2 - bn*p2^2 + br*p0^2 - br*p00^2...
%- bn*cn*p1 + bn*cn*p2 - br*cr*p0 + br*cr*p00 + dn*p1*tau - dn*p2*tau + dr*p0*tau - dr*p00*tau'];

soln = solve(myfun,'p1','p2','p0','p00','tau');
%turn structure into row vector then take transpose for easy reading
soln = [soln.p1 soln.p2 soln.p0 soln.p00 soln.tau]';
pretty(soln);


+- -+
| conj(x), conj(u) |
| |
| conj(u), conj(v) |
| |
| 8 an + 2 ar + 8 bn cn + 2 br cr - 16 bn conj(x) - 4 dn conj(v) - dr conj(v) |
| ---------------------------------------------------------------------------, conj(y) |
| 4 br |
| |
| conj(y), conj(x) |
| |
| conj(v), 0 |
+- -+


Published with MATLABĀ® 7.9

=============================================

Regards

Bruce