Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: how to convert a symbolic system into its matrix form
Replies: 2   Last Post: Apr 6, 2013 3:25 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Christopher Creutzig

Posts: 283
Registered: 2/24/09
Re: how to convert a symbolic system into its matrix form
Posted: Apr 4, 2013 5:10 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 14.03.13 18:18, pietro wrote:
> Hi all,
>
> I have a symbolic system and I have to convert it in its matrix form. As example:
>
> a*x+b*y=2;
> c*x+d*y=5;
>
> in
> [a,b;c,d]*[x;y]=[2;5];
>
> Is there anyway to perform that with matlab2012a? I know there is the function equationsToMatrix for the 2013a version, but unfortunately I don't have it. :(


You could try to make polynomial expressions from the equations with the
?children? function and then use ?quorem(lhs, x, x)? and ?quorem(lhs, y,
y)? to get the vectors to combine into the matrix. Not really pretty, I
know.


>> eqs = [a*x+b*y==2; c*x+d*y==5];
>> lhsrhs = children(eqs);
>> lhsrhs = cellfun(@(x) x(1)-x(2), lhsrhs, 'UniformOutput', false);
>> lhsrhs = [lhsrhs{:}].'


lhsrhs =

a*x + b*y - 2
c*x + d*y - 5

>> [quorem(lhsrhs, x, x), quorem(lhsrhs, y, y)]

ans =

[ a, b]
[ c, d]


HTH,
Christopher




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.