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:
solve

Subject: solve

From: Ben

Date: 14 Jul, 2010 17:11:56

Message: 1 of 3

Hello,

I don't know how to use the solve function. I've read the matlab doc, but I don't know how to solve this problem.

I have the following parameters.

a =-1;
b = 1.5;
c = 0;

I want to use this equation:
A = solve('a*cos(x) - b*sin(x)=c');

This gives:
A =
  (-2)*atan((b - (a^2 + b^2 - c^2)^(1/2))/(a + c))
  (-2)*atan((b + (a^2 + b^2 - c^2)^(1/2))/(a + c))

How can I get the answer in numbers between -pi and pi?

Subject: solve

From: Steven Lord

Date: 14 Jul, 2010 17:22:09

Message: 2 of 3


"Ben" <benvoeveren@gmail.com> wrote in message
news:279599969.28875.1279127546346.JavaMail.root@gallium.mathforum.org...
> Hello,
>
> I don't know how to use the solve function. I've read the matlab doc, but
> I don't know how to solve this problem.
>
> I have the following parameters.
>
> a =-1;
> b = 1.5;
> c = 0;
>
> I want to use this equation:
> A = solve('a*cos(x) - b*sin(x)=c');
>
> This gives:
> A =
> (-2)*atan((b - (a^2 + b^2 - c^2)^(1/2))/(a + c))
> (-2)*atan((b + (a^2 + b^2 - c^2)^(1/2))/(a + c))
>
> How can I get the answer in numbers between -pi and pi?

Use SUBS to substitute values into the expression.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: solve

From: Roger Stafford

Date: 15 Jul, 2010 01:13:06

Message: 3 of 3

Ben <benvoeveren@gmail.com> wrote in message <279599969.28875.1279127546346.JavaMail.root@gallium.mathforum.org>...
> Hello,
>
> I don't know how to use the solve function. I've read the matlab doc, but I don't know how to solve this problem.
>
> I have the following parameters.
>
> a =-1;
> b = 1.5;
> c = 0;
>
> I want to use this equation:
> A = solve('a*cos(x) - b*sin(x)=c');
>
> This gives:
> A =
> (-2)*atan((b - (a^2 + b^2 - c^2)^(1/2))/(a + c))
> (-2)*atan((b + (a^2 + b^2 - c^2)^(1/2))/(a + c))
>
> How can I get the answer in numbers between -pi and pi?
- - - - - - - -
  My symbolic toolbox came up with the same answer, Ben . However, this form of expression can produce a NaN where none ought to occur. For example, let a = 1, b = 1, and c = -1, which is a perfectly reasonable combination of values. However, the first of the two symbolic expressions when computed numerically with double precision numbers will give rise to a NaN because it involves a zero-divided-by-zero situation. This is an entirely artificial difficulty; there ought to be no trouble with that combination of values for a, b, and c.

  I much prefer the following two expressions:

A = [mod(atan2(b,-a)+acos(c/sqrt(a^2+b^2)),2*pi)-pi;
     mod(atan2(b,-a)-acos(c/sqrt(a^2+b^2)),2*pi)-pi]

These values will also always fall between -pi and +pi. The only accuracy difficulty this encounters occurs when c/sqrt(a^2+b^2) is very nearly +1 or -1, and that is inherent in the problem. A tiny change in c here makes a much larger change in x. The symbolic expressions also have the same difficulty in that circumstance.

Roger Stafford

Tags for this Thread

No tags are associated with 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