Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to convert a symbolic system into its matrix form

Subject: how to convert a symbolic system into its matrix form

From: pietro

Date: 14 Mar, 2013 17:18:05

Message: 1 of 3

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. :(

thanks

Best regards

Pietro

Subject: how to convert a symbolic system into its matrix form

From: Christopher Creutzig

Date: 4 Apr, 2013 09:10:45

Message: 2 of 3

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

Subject: how to convert a symbolic system into its matrix form

From: pietro

Date: 6 Apr, 2013 19:25:10

Message: 3 of 3

Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <515D4395.8020402@mathworks.com>...
> 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

Hi Christopher,

it's a really good idea. It works

Thanks

Cheers

Pietro

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us