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:
Wierd answer from Matlab using solve for simultaneous equations

Subject: Wierd answer from Matlab using solve for simultaneous equations

From: Yousuf Siddiqui

Date: 24 Jan, 2009 02:32:02

Message: 1 of 5

Hello,

When I tried to slove the following expression simultaneously it gave me a wierd answer.

>> solve('-2*c*cos(a)-6*c*sin(a)=16.78', 'c*cos(a)=0')

ans =

    a: [2x1 sym]
    c: [2x1 sym]

I do know sym, well actually syms is a command in the Matlab outlining symbolic expressions.

But I can't make any sense of the answer.

I have tried this over and over using clear and somtimes shuting down matlab, but still I get the same answer.

Subject: Wierd answer from Matlab using solve for simultaneous equations

From: Roger Stafford

Date: 24 Jan, 2009 02:52:01

Message: 2 of 5

"Yousuf Siddiqui" <engr.yousuf.siddiqui@gmail.com> wrote in message <glduj2$epv$1@fred.mathworks.com>...
> Hello,
>
> When I tried to slove the following expression simultaneously it gave me a wierd answer.
>
> >> solve('-2*c*cos(a)-6*c*sin(a)=16.78', 'c*cos(a)=0')
>
> ans =
>
> a: [2x1 sym]
> c: [2x1 sym]
>
> I do know sym, well actually syms is a command in the Matlab outlining symbolic expressions.
>
> But I can't make any sense of the answer.
>
> I have tried this over and over using clear and somtimes shuting down matlab, but still I get the same answer.

  That's strange! My matlab came through with the right answer. Did you declare a and c as sym variables?

Roger Stafford

Subject: Wierd answer from Matlab using solve for simultaneous equations

From: trancemissionxxi@gmail.com

Date: 24 Jan, 2009 02:56:50

Message: 3 of 5

On Jan 23, 6:32=A0pm, "Yousuf Siddiqui" <engr.yousuf.siddi...@gmail.com>
wrote:
> Hello,
>
> When I tried to slove the following expression simultaneously it gave me =
a wierd answer.
>
> >> solve('-2*c*cos(a)-6*c*sin(a)=3D16.78', =A0'c*cos(a)=3D0')
>
> ans =3D
>
> =A0 =A0 a: [2x1 sym]
> =A0 =A0 c: [2x1 sym]
>
> I do know sym, well actually syms is a command in the Matlab outlining sy=
mbolic expressions.
>
> But I can't make any sense of the answer.
>
> I have tried this over and over using clear and somtimes shuting down mat=
lab, but still I get the same answer.

Actually your answer is a structure. Try

mySolution=3Dsolve('-2*c*cos(a)-6*c*sin(a)=3D16.78', 'c*cos(a)=3D0');

and then display the fields with

mySolution.a

and

mySolution.c

Subject: Wierd answer from Matlab using solve for simultaneous equations

From: Yousuf Siddiqui

Date: 24 Jan, 2009 05:13:02

Message: 4 of 5

 
> Actually your answer is a structure. Try
>
> mySolution=3Dsolve('-2*c*cos(a)-6*c*sin(a)=3D16.78', 'c*cos(a)=3D0');
>
> and then display the fields with
>
> mySolution.a
>
> and
>
> mySolution.c

Your solution gives the following error

>> mySolution=3Dsolve('-2*c*cos(a)-6*c*sin(a)=3D16.78', 'c*cos(a)=3D0');
??? mySolution=3Dsolve('-2*c*cos(a)-6*c*sin(a)=3D16.78', 'c*cos(a)=3D0');
               |
Error: Unexpected MATLAB operator.

But you were right about the structures part. So I tried the following and it worked

>> S=solve('-2*c*cos(a)-6*c*sin(a)=16.78', 'c*cos(a)=0','a','c');
>> S.a
 
ans =
 
  1.5707963267948966192313216916398
 -1.5707963267948966192313216916398
 
 
>> S.c
 
ans =
 
 -2.7966666666666666666666666666667
  2.7966666666666666666666666666667

Thank you for your quick response and guiding me in the right path.

Subject: Wierd answer from Matlab using solve for simultaneous equations

From: Yousuf Siddiqui

Date: 24 Jan, 2009 05:14:01

Message: 5 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gldvoh$4g6$1@fred.mathworks.com>...
> "Yousuf Siddiqui" <engr.yousuf.siddiqui@gmail.com> wrote in message <glduj2$epv$1@fred.mathworks.com>...
> > Hello,
> >
> > When I tried to slove the following expression simultaneously it gave me a wierd answer.
> >
> > >> solve('-2*c*cos(a)-6*c*sin(a)=16.78', 'c*cos(a)=0')
> >
> > ans =
> >
> > a: [2x1 sym]
> > c: [2x1 sym]
> >
> > I do know sym, well actually syms is a command in the Matlab outlining symbolic expressions.
> >
> > But I can't make any sense of the answer.
> >
> > I have tried this over and over using clear and somtimes shuting down matlab, but still I get the same answer.
>
> That's strange! My matlab came through with the right answer. Did you declare a and c as sym variables?
>
> Roger Stafford


Sigh If only my matlab was as generous as yours. Thanks anyway.

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