From: Ben on
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?
From: Steven Lord on

"Ben" <benvoeveren(a)gmail.com> wrote in message
news:279599969.28875.1279127546346.JavaMail.root(a)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(a)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


From: Roger Stafford on
Ben <benvoeveren(a)gmail.com> wrote in message <279599969.28875.1279127546346.JavaMail.root(a)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