Problem in solving an equation symbolically

  • Follow


Hi all, 

I have this equation:

A*cos(theta)+B*sin(theta)=C. 

That I want to solve it symbolically, but matlab doesn't find any solution. I know the 
the solution is:

theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))

how can I solve it? 

Thanks
0
Reply bracardi82 (225) 6/9/2012 9:22:07 AM

On 6/9/2012 4:22 AM, pietro wrote:
> Hi all,
>
> I have this equation:
>
> A*cos(theta)+B*sin(theta)=C.
>
> That I want to solve it symbolically, but matlab doesn't find any solution. I know the
> the solution is:
>
> theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
>
> how can I solve it?
>
> Thanks

There are more solutions and conditions. Here is Mathematica answer


In[4]:= Assuming[Element[{a, b, c, theta}, Reals],
          Reduce[a*Cos[theta] + b*Sin[theta] - c == 0, theta]]


Out[4]= (Element[C[1], Integers] &&

  ((b != 0 && a^2 + b^2 != 0 && c == -a && theta == -2*ArcTan[a/b] + 2*Pi*C[1])

  ||

    (c == -a && theta == Pi + 2*Pi*C[1]))) || (Element[C[1], Integers] && a + c != 0 &&
    ((a^2 + b^2 + a*c - b*Sqrt[a^2 + b^2 - c^2] != 0 &&
    theta == 2*ArcTan[(b - Sqrt[a^2 + b^2 - c^2])/(a + c)] + 2*Pi*C[1])

||

     (a^2 + b^2 + a*c + b*Sqrt[a^2 + b^2 - c^2] != 0 &&
       theta == 2*ArcTan[(b + Sqrt[a^2 + b^2 - c^2])/(a + c)] + 2*Pi*C[1])))

||

   (NotElement[(-Pi + theta)/(2*Pi), Integers] && a == 0 && b == 0 && c == 0)

--Nasser
0
Reply Nasser 6/9/2012 9:56:00 AM


"pietro " <bracardi82@email.it> wrote in message <jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> Hi all, 
> 
> I have this equation:
> 
> A*cos(theta)+B*sin(theta)=C. 
> 
> That I want to solve it symbolically, but matlab doesn't find any solution. I know the 
> the solution is:
> 
> theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> 
> how can I solve it? 
> 
> Thanks

Pen an paper will suffice. The sum of angles formula
gives it all to you.

sin(x+y) = ...

John
0
Reply woodchips (7921) 6/9/2012 10:28:07 AM

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <jqv8fn$63d$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message <jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> > Hi all, 
> > 
> > I have this equation:
> > 
> > A*cos(theta)+B*sin(theta)=C. 
> > 
> > That I want to solve it symbolically, but matlab doesn't find any solution. I know the 
> > the solution is:
> > 
> > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > 
> > how can I solve it? 
> > 
> > Thanks
> 
> Pen an paper will suffice. The sum of angles formula
> gives it all to you.
> 
> sin(x+y) = ...
> 
> John

John thanks for your reply but I need to solve it symbolically through matlab for understanding more how matlab symbolic solver works and also because it's an equation of a system of equations, I have to solve symbolically.
0
Reply bracardi82 (225) 6/9/2012 1:13:08 PM

"pietro " <bracardi82@email.it> wrote in message 
<jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> Hi all, 
> 
> I have this equation:
> 
> A*cos(theta)+B*sin(theta)=C. 
> 
> That I want to solve it symbolically, but matlab doesn't find any solution.
> I know the  the solution is:
> 
> theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))

' 1. REPLACE arcos with acos'
' 2. Still is NOT a solution!;

 > how can I solve it? 

clear all, clc

syms A B C theta

theta = solve(A*cos(theta)+B*sin(theta)-C) 
 
% theta =
%  
%  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
%  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i

theta1 = -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
theta2 = -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;

err1 = simplify(A*cos(theta1)+B*sin(theta1)-C)  % 0
err2 = simplify(A*cos(theta2)+B*sin(theta2)-C)  % 0

' Check Pietro expressions'

 theta3 =+acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
 theta4 =-acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
  
err3 = simplify(A*cos(theta3)+B*sin(theta3)-C)  % NOT 0
err4 = simplify(A*cos(theta4)+B*sin(theta4)-C)  % NOT 0

err13 = simplify(theta1 - theta3)  % NOT 0
err14 = simplify(theta1 - theta4)  % NOT 0

So it looks like the Pieto expression is incorrect.

Hope this helps,

Greg
0
Reply heath (3882) 6/9/2012 6:55:07 PM

"Greg Heath" <heath@alumni.brown.edu> wrote in message <jr066b$ra6$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message 
> <jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> > Hi all, 
> > 
> > I have this equation:
> > 
> > A*cos(theta)+B*sin(theta)=C. 
> > 
> > That I want to solve it symbolically, but matlab doesn't find any solution.
> > I know the  the solution is:
> > 
> > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> 
> ' 1. REPLACE arcos with acos '
> ' 2. Still is NOT a solution! '
> 
>  > how can I solve it? 
> 
> clear all, clc
> 
> syms A B C theta
> 
> theta = solve(A*cos(theta)+B*sin(theta)-C) 
>  
> % theta =
> %  
> %  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> %  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> 
> theta1 = -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> theta2 = -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> 
> err1 = simplify(A*cos(theta1)+B*sin(theta1)-C)  % 0
> err2 = simplify(A*cos(theta2)+B*sin(theta2)-C)  % 0
> 
> ' Check Pietro expressions'
> 
>  theta3 =+acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
>  theta4 =-acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
>   
> err3 = simplify(A*cos(theta3)+B*sin(theta3)-C)  % NOT 0
> err4 = simplify(A*cos(theta4)+B*sin(theta4)-C)  % NOT 0
> 
> err13 = simplify(theta1 - theta3)  % NOT 0
> err14 = simplify(theta1 - theta4)  % NOT 0
> 
> So it looks like the Pieto expression is incorrect.

'Wait. Only checked two sign possibilities (+/-with +/-)'
'Now checking the other two sign possibilities (+/- with -/+)'

theta5 =+acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
theta6 =-acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))

err5 = simplify(A*cos(theta5)+B*sin(theta5)-C)  % NOT 0
err6 = simplify(A*cos(theta6)+B*sin(theta6)-C)  % NOT 0

err15 = simplify(theta1 - theta5)  % NOT 0
err16 = simplify(theta1 - theta6)  % NOT 0

However, there may be two more solutions associated with sign changes 
in theta1 and theta2.

Hope this helps,
 
Greg
0
Reply heath (3882) 6/10/2012 1:31:09 AM

"Greg Heath" <heath@alumni.brown.edu> wrote in message <jr0tct$oip$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr066b$ra6$1@newscl01ah.mathworks.com>...
> > "pietro " <bracardi82@email.it> wrote in message 
> > <jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> > > Hi all, 
> > > 
> > > I have this equation:
> > > 
> > > A*cos(theta)+B*sin(theta)=C. 
> > > 
> > > That I want to solve it symbolically, but matlab doesn't find any solution.
> > > I know the  the solution is:
> > > 
> > > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > 
> > ' 1. REPLACE arcos with acos '
> > ' 2. Still is NOT a solution! '
> > 
> >  > how can I solve it? 
> > 
> > clear all, clc
> > 
> > syms A B C theta
> > 
> > theta = solve(A*cos(theta)+B*sin(theta)-C) 
> >  
> > % theta =
> > %  
> > %  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> > %  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> > 
> > theta1 = -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> > theta2 = -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> > 
> > err1 = simplify(A*cos(theta1)+B*sin(theta1)-C)  % 0
> > err2 = simplify(A*cos(theta2)+B*sin(theta2)-C)  % 0
> > 
> > ' Check Pietro expressions'
> > 
> >  theta3 =+acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
> >  theta4 =-acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> >   
> > err3 = simplify(A*cos(theta3)+B*sin(theta3)-C)  % NOT 0
> > err4 = simplify(A*cos(theta4)+B*sin(theta4)-C)  % NOT 0
> > 
> > err13 = simplify(theta1 - theta3)  % NOT 0
> > err14 = simplify(theta1 - theta4)  % NOT 0
> > 
> > So it looks like the Pieto expression is incorrect.
> 
> 'Wait. Only checked two sign possibilities (+/-with +/-)'
> 'Now checking the other two sign possibilities (+/- with -/+)'
> 
> theta5 =+acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> theta6 =-acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
> 
> err5 = simplify(A*cos(theta5)+B*sin(theta5)-C)  % NOT 0
> err6 = simplify(A*cos(theta6)+B*sin(theta6)-C)  % NOT 0
> 
> err15 = simplify(theta1 - theta5)  % NOT 0
> err16 = simplify(theta1 - theta6)  % NOT 0
> 
> However, there may be two more solutions associated with sign changes 
> in theta1 and theta2.
> 
> Hope this helps,
>  
> Greg

Hi Greg, 

thanks for your reply. I found the formula on a book. So I should have used semplify instead of solve.  This formula arise from this system of equations

r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)=0
r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)=0

but matlab can't solve this system. 

This is the code I have used:

syms r1 r2 r3 r4 theta_1 theta_2 theta_3 theta_4

S=solve(r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4),r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4),theta_3,theta_4)


Thanks best regards

Michele
0
Reply bracardi82 (225) 6/10/2012 11:10:08 AM

"pietro " <bracardi82@email.it> wrote in message  
> 
> thanks for your reply. I found the formula on a book. So I should have used semplify instead of solve.  This formula arise from this system of equations
> 
> r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)=0
> r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)=0

No software can solve for four unknowns with just two equations.

Bruno
0
Reply b.luong5955 (6359) 6/10/2012 11:30:09 AM

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr20g1$5tj$1@newscl01ah.mathworks.com>...
> "pietro " <bracardi82@email.it> wrote in message  
> > 
> > thanks for your reply. I found the formula on a book. So I should have used semplify instead of solve.  This formula arise from this system of equations
> > 
> > r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)=0
> > r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)=0
> 
> No software can solve for four unknowns with just two equations.
> 
> Bruno

Hi Bruno, 

the variables are theta_3 and theta_4...
0
Reply bracardi82 (225) 6/10/2012 11:50:08 AM

"pietro " <bracardi82@email.it> wrote in message <jr21lf$a6t$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr20g1$5tj$1@newscl01ah.mathworks.com>...
> > "pietro " <bracardi82@email.it> wrote in message  
> > > 
> > > thanks for your reply. I found the formula on a book. So I should have used semplify instead of solve.  This formula arise from this system of equations
> > > 
> > > r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)=0
> > > r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)=0
> > 
> > No software can solve for four unknowns with just two equations.
> > 
> > Bruno
> 
> Hi Bruno, 
> 
> the variables are theta_3 and theta_4...

Then pencil & paper is enough.

r1 = rand;
r2 = rand;
r3 = rand;
r4 = rand;
theta_1 = 2*pi*rand;
theta_2 = 2*pi*rand;

% Solve
a = r1*cos(theta_1)+r2*cos(theta_2);
b = r1*sin(theta_1)+r2*sin(theta_2);
c = sqrt(a^2+b^2) / r3;
d = r4 / r3;
x = (c^2 - d^2 + 1) / (2*c);
if abs(x) > 1
    error('no solution')
end

theta_3 = acos(x); % second solution by setting here theta_3 = -acos(x);
theta_4 = atan2(-sin(theta_3), c-x);
alpha = atan2(b,a);
theta_3 = alpha + theta_3
theta_4 = alpha + theta_4

% Check
r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)
r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)

% Follow the code, then it gives you the analytical formula that you can put back to whatever symbolic engine if needed

% Bruno
0
Reply b.luong5955 (6359) 6/10/2012 3:42:07 PM

"pietro " <bracardi82@email.it> wrote in message <jr1vag$1i6$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr0tct$oip$1@newscl01ah.mathworks.com>...
> > "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr066b$ra6$1@newscl01ah.mathworks.com>...
> > > "pietro " <bracardi82@email.it> wrote in message 
> > > <jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> > > > Hi all, 
> > > > 
> > > > I have this equation:
> > > > 
> > > > A*cos(theta)+B*sin(theta)=C. 
> > > > 
> > > > That I want to solve it symbolically, but matlab doesn't find any solution.
> > > > I know the  the solution is:
> > > > 
> > > > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > > 
> > > ' 1. REPLACE arcos with acos '
> > > ' 2. Still is NOT a solution! '
> > > 
> > >  > how can I solve it? 
> > > 
> > > clear all, clc
> > > 
> > > syms A B C theta
> > > 
> > > theta = solve(A*cos(theta)+B*sin(theta)-C) 
> > >  
> > > % theta =
> > > %  
> > > %  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> > > %  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> > > 
> > > theta1 = -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> > > theta2 = -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> > > 
> > > err1 = simplify(A*cos(theta1)+B*sin(theta1)-C)  % 0
> > > err2 = simplify(A*cos(theta2)+B*sin(theta2)-C)  % 0
> > > 
> > > ' Check Pietro expressions'
> > > 
> > >  theta3 =+acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > >  theta4 =-acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > >   
> > > err3 = simplify(A*cos(theta3)+B*sin(theta3)-C)  % NOT 0
> > > err4 = simplify(A*cos(theta4)+B*sin(theta4)-C)  % NOT 0
> > > 
> > > err13 = simplify(theta1 - theta3)  % NOT 0
> > > err14 = simplify(theta1 - theta4)  % NOT 0
> > > 
> > > So it looks like the Pieto expression is incorrect.
> > 
> > 'Wait. Only checked two sign possibilities (+/-with +/-)'
> > 'Now checking the other two sign possibilities (+/- with -/+)'
> > 
> > theta5 =+acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > theta6 =-acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > 
> > err5 = simplify(A*cos(theta5)+B*sin(theta5)-C)  % NOT 0
> > err6 = simplify(A*cos(theta6)+B*sin(theta6)-C)  % NOT 0
> > 
> > err15 = simplify(theta1 - theta5)  % NOT 0
> > err16 = simplify(theta1 - theta6)  % NOT 0
> > 
> > However, there may be two more solutions associated with sign changes 
> > in theta1 and theta2.
> > 
> > Hope this helps,
> >  
> > Greg
> 
> Hi Greg, 
> 
> thanks for your reply. I found the formula on a book. 

But, the formula you gave is not a solution to the equation you gave!

What is the correct equation ??

>So I should have used semplify instead of solve.  

No. 

SOLVE is used to obtain the solutions.

SIMPLIFY is used to prove that the solutions obey the equation.

>This formula arise from this system of equations
> 
> r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)=0
> r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)=0
>
> but matlab can't solve this system. 

I don't understand. For one variable the system  reduces to the form

a - r4*cos(theta) = 0
b - r4*sin(theta)  = 0

which has ONE unique solution 

theta = atan(a/r4,b/r4)

> This is the code I have used:
> 
> syms r1 r2 r3 r4 theta_1 theta_2 theta_3 theta_4
> 
> S=solve(r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4),r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4),theta_3,theta_4)

You can only solve for two of the unknowns. However, you can choose one of the r 
coefficients to be zero or 1.

Hope this helps.

Greg
0
Reply heath (3882) 6/10/2012 11:09:06 PM

"pietro " <bracardi82@email.it> wrote in message <jr1vag$1i6$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr0tct$oip$1@newscl01ah.mathworks.com>...
> > "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr066b$ra6$1@newscl01ah.mathworks.com>...
> > > "pietro " <bracardi82@email.it> wrote in message 
> > > <jqv4jv$ln1$1@newscl01ah.mathworks.com>...
> > > > Hi all, 
> > > > 
> > > > I have this equation:
> > > > 
> > > > A*cos(theta)+B*sin(theta)=C. 
> > > > 
> > > > That I want to solve it symbolically, but matlab doesn't find any solution.
> > > > I know the  the solution is:
> > > > 
> > > > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > > 
> > > ' 1. REPLACE arcos with acos '
> > > ' 2. Still is NOT a solution! '
> > > 
> > >  > how can I solve it? 
> > > 
> > > clear all, clc
> > > 
> > > syms A B C theta
> > > 
> > > theta = solve(A*cos(theta)+B*sin(theta)-C) 
> > >  
> > > % theta =
> > > %  
> > > %  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> > > %  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> > > 
> > > theta1 = -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> > > theta2 = -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i ;
> > > 
> > > err1 = simplify(A*cos(theta1)+B*sin(theta1)-C)  % 0
> > > err2 = simplify(A*cos(theta2)+B*sin(theta2)-C)  % 0
> > > 
> > > ' Check Pietro expressions'
> > > 
> > >  theta3 =+acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > >  theta4 =-acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > >   
> > > err3 = simplify(A*cos(theta3)+B*sin(theta3)-C)  % NOT 0
> > > err4 = simplify(A*cos(theta4)+B*sin(theta4)-C)  % NOT 0
> > > 
> > > err13 = simplify(theta1 - theta3)  % NOT 0
> > > err14 = simplify(theta1 - theta4)  % NOT 0
> > > 
> > > So it looks like the Pieto expression is incorrect.
> > 
> > 'Wait. Only checked two sign possibilities (+/-with +/-)'
> > 'Now checking the other two sign possibilities (+/- with -/+)'
> > 
> > theta5 =+acos((B*C-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > theta6 =-acos((B*C+sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > 
> > err5 = simplify(A*cos(theta5)+B*sin(theta5)-C)  % NOT 0
> > err6 = simplify(A*cos(theta6)+B*sin(theta6)-C)  % NOT 0
> > 
> > err15 = simplify(theta1 - theta5)  % NOT 0
> > err16 = simplify(theta1 - theta6)  % NOT 0
> > 
> > However, there may be two more solutions associated with sign changes 
> > in theta1 and theta2.
> > 
> > Hope this helps,
> >  
> > Greg
> 
> Hi Greg, 
> 
> thanks for your reply. I found the formula on a book. So I should have used semplify instead of solve.  This formula arise from this system of equations
> 
> r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4)=0
> r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4)=0
> 
> but matlab can't solve this system. 
> 
> This is the code I have used:
> 
> syms r1 r2 r3 r4 theta_1 theta_2 theta_3 theta_4
> 
> S=solve(r1*cos(theta_1)+r2*cos(theta_2)-r3*cos(theta_3)-r4*cos(theta_4),r1*sin(theta_1)+r2*sin(theta_2)-r3*sin(theta_3)-r4*sin(theta_4),theta_3,theta_4)
> 
> 
> Thanks best regards
> 
> Michele
0
Reply heath (3882) 6/10/2012 11:10:07 PM

"Greg Heath" <heath@alumni.brown.edu> wrote in message 
> 
> I don't understand. For one variable the system  reduces to the form
> 
> a - r4*cos(theta) = 0
> b - r4*sin(theta)  = 0
> 
> which has ONE unique solution 
> 
> theta = atan(a/r4,b/r4)

You probably mean atan2(). Your statement is still not right. Solution exists only if (a/r4)^2 + (b/r4)^2 = 1.

OP said that theta_3 and theta_4 are unknown.

Bruno
0
Reply b.luong5955 (6359) 6/11/2012 12:58:06 AM

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr3fqu$4ee$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message 
> > 
> > I don't understand. For one variable the system  reduces to the form
> > 
> > a - r4*cos(theta) = 0
> > b - r4*sin(theta)  = 0
> > 
> > which has ONE unique solution 
> > 
> > theta = atan(a/r4,b/r4)
> 
> You probably mean atan2(). 

No. Double input atan is correct for symbolic arguments whereas atan2 is not defined and causes uses an error. 

>Your statement is still not right. Solution exists only if (a/r4)^2 + (b/r4)^2 = 1.

Agree: Two equations, one unknown. 

> OP said that theta_3 and theta_4 are unknown.

I was referring to the fact that, for one unknown, the equations reduce to the two equations above. If if your constraint holds, then a single solution exists.

However, the OP appeared to combine them to obtain the single equation

A*sin(theta)+B*sin(theta) = C 

for which matlab yields the two solutions that I gave.

Hope this helps.

Greg
0
Reply heath (3882) 6/11/2012 3:06:07 AM

"pietro " <bracardi82@email.it> wrote in message 
news:jqv4jv$ln1$1@newscl01ah.mathworks.com...
> Hi all,
> I have this equation:
>
> A*cos(theta)+B*sin(theta)=C.
> That I want to solve it symbolically, but matlab doesn't find any 
> solution. I know the the solution is:
>
> theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
>
> how can I solve it?
> Thanks

I solved this in R2012A:

syms theta A B C
 sol = solve(A*cos(theta)+B*sin(theta)==C, theta)
sol =
 -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
 -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*I

--Loren
http://blogs.mathworks.com/loren/
http://www.mathworks.com/matlabcentral/ 

0
Reply loren.shure (822) 6/11/2012 8:37:16 AM

On 6/11/2012 3:37 AM, Loren Shure wrote:

> I solved this in R2012A:
>
> syms theta A B C
>   sol = solve(A*cos(theta)+B*sin(theta)==C, theta)
> sol =
>   -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
>   -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*I
>
> --Loren
> http://blogs.mathworks.com/loren/
> http://www.mathworks.com/matlabcentral/
>

hi;

fyi, I posted earlier Mathematica Reduce answer.
Here is its Solve answer to compare. It finds 4 solutions

(I used x instead of theta)

In[333]:= Solve[a*Cos[x] + b*Sin[x] == c, x]

{x -> -ArcCos[(a*c - Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]},
{x -> ArcCos[(a*c - Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]},
{x -> -ArcCos[(a*c + Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]},
{x -> ArcCos[(a*c + Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]}}

But note the warning:

During evaluation of In[333]:= Solve::ifun:Inverse functions are
being used by Solve, so some solutions may not be found;
use Reduce for complete solution information. >>


--Nasser
0
Reply Nasser 6/11/2012 9:35:18 AM

"Loren Shure" wrote in message <jr4ans$g23$1@newscl01ah.mathworks.com>...
> 
> "pietro " <bracardi82@email.it> wrote in message 
> news:jqv4jv$ln1$1@newscl01ah.mathworks.com...
> > Hi all,
> > I have this equation:
> >
> > A*cos(theta)+B*sin(theta)=C.
> > That I want to solve it symbolically, but matlab doesn't find any 
> > solution. I know the the solution is:
> >
> > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> >
> > how can I solve it?
> > Thanks
> 
> I solved this in R2012A:
> 
> syms theta A B C
>  sol = solve(A*cos(theta)+B*sin(theta)==C, theta)
> sol =
>  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
>  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*I

Yes. Those are the same solutions I obtained previously with 2011b.
However,

Bruno used Mathematica to obtain four solutions in the form of 
inverse trig functions.

Is there any way to use symbolic matlab to 

1. Convert the log form to inv trig?
2. Obtain the other two solutions?

Hope ths helps.

Greg
0
Reply heath (3882) 6/11/2012 4:40:07 PM

"Greg Heath" <heath@alumni.brown.edu> wrote in message 
> 
> Bruno used Mathematica to obtain four solutions in the form of 
> inverse trig functions.

It's Nasser who runs Mathematica.

I prefer pencil and paper. ;-)

Bruno
0
Reply b.luong5955 (6359) 6/11/2012 6:20:08 PM

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr5cso$fab$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message 
> > 
> > Bruno used Mathematica to obtain four solutions in the form of 
> > inverse trig functions.
> 
> It's Nasser who runs Mathematica.
> 
> I prefer pencil and paper. ;-)
> 
> Bruno

Whoops! ... My Bad

Greg
0
Reply heath (3882) 6/11/2012 10:23:06 PM

"Nasser M. Abbasi" <nma@12000.org> wrote in message <jr4e4l$qdp$1@speranza.aioe.org>...
> On 6/11/2012 3:37 AM, Loren Shure wrote:
> 
> > I solved this in R2012A:
> >
> > syms theta A B C
> >   sol = solve(A*cos(theta)+B*sin(theta)==C, theta)
> > sol =
> >   -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> >   -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*I
> >
> > --Loren
> > http://blogs.mathworks.com/loren/
> > http://www.mathworks.com/matlabcentral/
> >
> 
> hi;
> 
> fyi, I posted earlier Mathematica Reduce answer.
> Here is its Solve answer to compare. It finds 4 solutions
> 
> (I used x instead of theta)
> 
> In[333]:= Solve[a*Cos[x] + b*Sin[x] == c, x]
> 
> {x -> -ArcCos[(a*c - Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]},
> {x -> ArcCos[(a*c - Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]},
> {x -> -ArcCos[(a*c + Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]},
> {x -> ArcCos[(a*c + Sqrt[a^2*b^2 + b^4 - b^2*c^2])/(a^2 + b^2)]}}
> 
> But note the warning:
> 
> During evaluation of In[333]:= Solve::ifun:Inverse functions are
> being used by Solve, so some solutions may not be found;
> use Reduce for complete solution information. 

Rearranging for an easy comparison with Pietro's expression yields

(+/-)ArcCos{ ( "a" *c (+/-) "b" * Sqrt[a^2 + b^2 - c^2] ) / (a^2 + b^2) }

instead of 

(+/-)ArcCos{ ( "b" *c (+/-) "1" * Sqrt[a^2 + b^2 - c^2] ) / (a^2 + b^2) }

Hope this helps.

Greg
0
Reply heath (3882) 6/11/2012 10:53:06 PM

"Greg Heath" <heath@alumni.brown.edu> wrote in message <jr5717$hno$1@newscl01ah.mathworks.com>...
> "Loren Shure" wrote in message <jr4ans$g23$1@newscl01ah.mathworks.com>...
> > 
> > "pietro " <bracardi82@email.it> wrote in message 
> > news:jqv4jv$ln1$1@newscl01ah.mathworks.com...
> > > Hi all,
> > > I have this equation:
> > >
> > > A*cos(theta)+B*sin(theta)=C.
> > > That I want to solve it symbolically, but matlab doesn't find any 
> > > solution. I know the the solution is:
> > >
> > > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > >
> > > how can I solve it?
> > > Thanks
> > 
> > I solved this in R2012A:
> > 
> > syms theta A B C
> >  sol = solve(A*cos(theta)+B*sin(theta)==C, theta)
> > sol =
> >  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> >  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*I
> 
> Yes. Those are the same solutions I obtained previously with 2011b.
> However,
> 
> Nasser used Mathematica to obtain four solutions in the form of 
> inverse trig functions.
> 
> Is there any way to use Symbolic Matlab to 
> 
> 1. Convert the log form to inv trig?
> 2. Obtain the other two solutions?

More importantly, why doesn't Symbolic Matlab recognize Nasser's expressions as solutions?
 
clear all, clc

syms a b c x

x1 = acos((a*c + sqrt(a^2*b^2 + b^4 - b^2*c^2))/(a^2 + b^2))
err1 = simplify(a*cos(x1)+b*sin(x1)-c) % NOT ZERO?

x2 = acos((a*c - sqrt(a^2*b^2 + b^4 - b^2*c^2))/(a^2 + b^2))
err2 = simplify(a*cos(x2)+b*sin(x2)-c) % NOT ZERO?

x3 = -acos((a*c + sqrt(a^2*b^2 + b^4 - b^2*c^2))/(a^2 + b^2))
err3 = simplify(a*cos(x3)+b*sin(x3)-c) % NOT ZERO?

x4 = -acos((a*c - sqrt(a^2*b^2 + b^4 - b^2*c^2))/(a^2 + b^2))
err4 = simplify(a*cos(x4)+b*sin(x4)-c) % NOT ZERO?

Hope this helps.
 
Greg
0
Reply heath (3882) 6/11/2012 11:32:07 PM

On 6/11/2012 6:32 PM, Greg Heath wrote:


> More importantly, why doesn't Symbolic Matlab recognize Nasser's expressions as solutions?
>
> clear all, clc
>
> syms a b c x
>
> x1 = acos((a*c + sqrt(a^2*b^2 + b^4 - b^2*c^2))/(a^2 + b^2))
> err1 = simplify(a*cos(x1)+b*sin(x1)-c) % NOT ZERO?
>

I think this is because the solution given by Mathematica's Solve
does not show the assumptions on a,b,c that are needed.

That is why I used Reduce earlier.  Just to clarify, I show
below one solution, then show the equation when this one solution
is substituted back into it. Then use the assumptions needed to
show that it does show ZERO.

One can now clearly see that the result is only zero under certain
conditions on a,b,c.

Lets start from the top. First solve it

--------------------------
Clear[a,b,c]
eq  = a*Cos[x]+b*Sin[x]-c;
sol = Solve[eq==0,x];
sol = x/.sol
-------------------------

    {-ArcCos[(a c-Sqrt[a^2 b^2+b^4-b^2 c^2])/(a^2+b^2)],
      ArcCos[(a c-Sqrt[a^2 b^2+b^4-b^2 c^2])/(a^2+b^2)],
      -ArcCos[(a c+Sqrt[a^2 b^2+b^4-b^2 c^2])/(a^2+b^2)],
      ArcCos[(a c+Sqrt[a^2 b^2+b^4-b^2 c^2])/(a^2+b^2)]}

So, 4 solutions. substituting the first solution back into
the equation

-----------------------
eq/.x->sol[[1]]    (*replace first solution back in equation *)
-----------------------

gives

-c+(a (a c-Sqrt[a^2 b^2+b^4-b^2 c^2]))/(a^2+b^2)
-b Sqrt[1-(a c-Sqrt[a^2 b^2+b^4-b^2 c^2])^2/(a^2+b^2)^2]

Notice the denominator term (a^2+b^2). So the only
way for this to be zero, is for the left term to be
equal to the right term. Since  "A/z^2" on its own can't
be zero unless z->Infinity.

So the condition for zero is

-c+(a (a c-Sqrt[a^2 b^2+b^4-b^2 c^2]))/(a^2+b^2)

must equal

b Sqrt[1-(a c-Sqrt[a^2 b^2+b^4-b^2 c^2])^2/(a^2+b^2)^2]

So these solutions are valid in a very small
region in the space of values of a,b,c.

The answer given by Reduce contained the full set of assumptions
taking care of branch cuts in the trig functions.

For example, using one assumption given before, shows the
solution is valid

Assuming[Element[{a,b},Reals]&&b!=0&&a^2+b^2!=0&&c==-a,
            Simplify[eq/.x->sol[[1]]]]

     0

So to do this in Matlab syms, the simplify command
needs to include similar assumptions. I do not know
now how to Matlab simplify that

     Element[{a,b},Reals] && b!=0 && a^2+b^2!=0 && c==-a

I need to have more coeffee and will try later if I can.

--Nasser
0
Reply Nasser 6/12/2012 1:08:22 AM

"Greg Heath" <heath@alumni.brown.edu> wrote in message 
> 
> Bruno used Mathematica to obtain four solutions in the form of 
> inverse trig functions.

It's Nasser who runs Mathematica.

I prefer pencil and paper. ;-)

Bruno
0
Reply b.luong5955 (6359) 6/12/2012 7:38:07 AM

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr6rkv$n9l$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message 
> > 
> > Bruno used Mathematica to obtain four solutions in the form of 
> > inverse trig functions.
> 
> It's Nasser who runs Mathematica.
> 
> I prefer pencil and paper. ;-)

OK. Let's try the original equation

a*cos(x) + b*sin(x) = c      %   a^2+b^2 > 0

Define s1, s2, d, y

s1 = (+/-)1                      %    either/or
s2 = (+/-)1                      %    independent of s1
d  = sqrt(a^2+b^2)         %    d > 0
y  = s1*acos(a/d)

Then

a = d*cos(s1*y)
b = s2*d*sin(s1*y)

cos(s1*y)*cos(x) + s2*sin(s1*y)*sin(x) = c/d

cos(x-s2*s1y) = c/d

x =s2*s1*y + acos(c/d)

x =s2*acos(a/d) + acos(c/d)

Only two solutions

clear all, clc
syms a b c d x1 x2 

d      = sqrt(a^2+b^2)
x1     = acos(a/d)+acos(c/d)
err1 = simplify(a*cos(x1) + b*sin(x1) - c) % NOT ZERO ??
x2    = -acos(a/d)+acos(c/d)
err1 = simplify(a*cos(x2) + b*sin(x2) - c) % NOT ZERO ??

What am I missing?

Greg
0
Reply heath (3882) 6/12/2012 10:46:07 AM

"Greg Heath" <heath@alumni.brown.edu> wrote in message <jr76lf$5t4$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr6rkv$n9l$1@newscl01ah.mathworks.com>...
> > "Greg Heath" <heath@alumni.brown.edu> wrote in message 
> > > 
> > > Bruno used Mathematica to obtain four solutions in the form of 
> > > inverse trig functions.
> > 
> > It's Nasser who runs Mathematica.
> > 
> > I prefer pencil and paper. ;-)
> 
> OK. Let's try the original equation
> 
> a*cos(x) + b*sin(x) = c      %   a^2+b^2 > 0
> 
> Define s1, s2, d, y
> 
> s1 = (+/-)1                      %    either/or
> s2 = (+/-)1                      %    independent of s1
> d  = sqrt(a^2+b^2)         %    d > 0
> y  = s1*acos(a/d)
> 
> Then
> 
> a = d*cos(s1*y)
> b = s2*d*sin(s1*y)

then sign(b) = sign(s2)*sign(s1) = s1*s2

s1 and s2 are not independent then as planned.

I do not examine read the rest.

Bruno
0
Reply b.luong5955 (6359) 6/13/2012 7:15:07 AM

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr9elr$adj$1@newscl01ah.mathworks.com>...
> "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr76lf$5t4$1@newscl01ah.mathworks.com>...
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr6rkv$n9l$1@newscl01ah.mathworks.com>...
> > > "Greg Heath" <heath@alumni.brown.edu> wrote in message 
> > > > 
> > > > Bruno used Mathematica to obtain four solutions in the form of 
> > > > inverse trig functions.
> > > 
> > > It's Nasser who runs Mathematica.
> > > 
> > > I prefer pencil and paper. ;-)
> > 
> > OK. Let's try the original equation
> > 
> > a*cos(x) + b*sin(x) = c      %   a^2+b^2 > 0
> > 
> > Define s1, s2, d, y
> > 
> > s1 = (+/-)1                      %    either/or
> > s2 = (+/-)1                      %    independent of s1
> > d  = sqrt(a^2+b^2)         %    d > 0
> > y  = s1*acos(a/d)
> > 
> > Then
> > 
> > a = d*cos(s1*y)
> > b = s2*d*sin(s1*y)
> 
> then sign(b) = sign(s2)*sign(s1) = s1*s2
> 
> s1 and s2 are not independent then as planned.

OK. Let's try again

a*cos(x) + s*b*sin(x) = c      %   0 < a, b  <=1 , s = (+/-)1

Existence of real x solution constraint

abs(c) <=  a + b

Define d,y

d = sqrt(a^2+b^2)                %    d  > 0
y = acos(a/d)                       %   0 <= y < pi/2

Then

a = d*cos(y)
b = d*sin(y)

cos(y)*cos(x) + s*sin(y)*sin(x) = c/d

cos(x-sy) = c/d

x = s*y + acos(c/d)

x = s*acos(a/d) + acos(c/d)

Only two solutions

clear all, clc
syms a b c d x1 x2 

d      = sqrt(a^2+b^2)
x1     = acos(a/d)+acos(c/d)
err1 = simplify(a*cos(x1) + b*sin(x1) - c) % NOT ZERO ??
err1 ~= 0                                                % = 1 => NOT ZERO
x2    = -acos(a/d)+acos(c/d)
err2 = simplify(a*cos(x2) - b*sin(x2) - c) % NOT ZERO ??
err2 ~= 0                                               % = 1=>  NOT ZERO

What am I missing?

Greg
0
Reply heath (3882) 6/13/2012 2:12:09 PM

"Greg Heath" <heath@alumni.brown.edu> wrote in message <jra73p$ki5$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr9elr$adj$1@newscl01ah.mathworks.com>...
> > "Greg Heath" <heath@alumni.brown.edu> wrote in message <jr76lf$5t4$1@newscl01ah.mathworks.com>...
> > > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jr6rkv$n9l$1@newscl01ah.mathworks.com>...
> > > > "Greg Heath" <heath@alumni.brown.edu> wrote in message 
> > > > > 
> > > > > Bruno used Mathematica to obtain four solutions in the form of 
> > > > > inverse trig functions.
> > > > 
> > > > It's Nasser who runs Mathematica.
> > > > 
> > > > I prefer pencil and paper. ;-)
> > > 
> > > OK. Let's try the original equation
> > > 
> > > a*cos(x) + b*sin(x) = c      %   a^2+b^2 > 0
> > > 
> > > Define s1, s2, d, y
> > > 
> > > s1 = (+/-)1                      %    either/or
> > > s2 = (+/-)1                      %    independent of s1
> > > d  = sqrt(a^2+b^2)         %    d > 0
> > > y  = s1*acos(a/d)
> > > 
> > > Then
> > > 
> > > a = d*cos(s1*y)
> > > b = s2*d*sin(s1*y)
> > 
> > then sign(b) = sign(s2)*sign(s1) = s1*s2
> > 
> > s1 and s2 are not independent then as planned.
> 
> OK. Let's try again
> 
> a*cos(x) + s*b*sin(x) = c      %   0 < a, b  <=1 , s = (+/-)1
> 
> Existence of real x solution constraint
> 
> abs(c) <=  a + b
> 
> Define d,y
> 
> d = sqrt(a^2+b^2)                %    d  > 0
> y = acos(a/d)                       %   0 <= y < pi/2
> 
> Then
> 
> a = d*cos(y)
> b = d*sin(y)
> 
> cos(y)*cos(x) + s*sin(y)*sin(x) = c/d
> 
> cos(x-sy) = c/d
> 
> x = s*y + acos(c/d)
> 
> x = s*acos(a/d) + acos(c/d)
> 
> Only two solutions
> 
> clear all, clc
> syms a b c d x1 x2 
> 
> d      = sqrt(a^2+b^2)
> x1     = acos(a/d)+acos(c/d)
> err1 = simplify(a*cos(x1) + b*sin(x1) - c) % NOT ZERO ??
> err1 ~= 0                                                % = 1 => NOT ZERO
> x2    = -acos(a/d)+acos(c/d)
> err2 = simplify(a*cos(x2) - b*sin(x2) - c) % NOT ZERO ??
> err2 ~= 0                                               % = 1=>  NOT ZERO
> 
> What am I missing?
 
Do I have to feed symbolic Matlab the following constraints?

0 < a <= 1
0 < b <= 1
abs(c) < a + b

If so, how?

 Greg
0
Reply heath (3882) 6/13/2012 3:48:07 PM

On 13.06.12 17:48, Greg Heath wrote:

>> clear all, clc
>> syms a b c d x1 x2 
>> 
>> d      = sqrt(a^2+b^2)
>> x1     = acos(a/d)+acos(c/d)
>> err1 = simplify(a*cos(x1) + b*sin(x1) - c) % NOT ZERO ??
>> err1 ~= 0                                                % = 1 => NOT ZERO
>> x2    = -acos(a/d)+acos(c/d)
>> err2 = simplify(a*cos(x2) - b*sin(x2) - c) % NOT ZERO ??
>> err2 ~= 0                                               % = 1=>  NOT ZERO
>> 
>> What am I missing?
>  
> Do I have to feed symbolic Matlab the following constraints?
> 
> 0 < a <= 1
> 0 < b <= 1
> abs(c) < a + b

That helps, yes.

> If so, how?

Assuming a sufficiently recent installation:

assume(0<a);
assumeAlso(a<=1);
assume(0<b);
assumeAlso(b<=1);
assumeAlso(abs(c)<a+b);
simplify(err1)

ans =

0

simplify(err2)

ans =

0


You can replace “assume(0<a)” by “syms a positive”, if you prefer. The
assume/assumeAlso calls are, however, much more flexible.



Christopher
0
Reply Christopher.Creutzig1 (220) 6/14/2012 3:09:08 PM

"Greg Heath" <heath@alumni.brown.edu> wrote in message <jr5717$hno$1@newscl01ah.mathworks.com>...
> "Loren Shure" wrote in message <jr4ans$g23$1@newscl01ah.mathworks.com>...
> > 
> > "pietro " <bracardi82@email.it> wrote in message 
> > news:jqv4jv$ln1$1@newscl01ah.mathworks.com...
> > > Hi all,
> > > I have this equation:
> > >
> > > A*cos(theta)+B*sin(theta)=C.
> > > That I want to solve it symbolically, but matlab doesn't find any 
> > > solution. I know the the solution is:
> > >
> > > theta=+/-arcos((B*C+/-sqrt(A^2+B^2-C^2))/(A^2+B^2))
> > >
> > > how can I solve it?
> > > Thanks
> > 
> > I solved this in R2012A:
> > 
> > syms theta A B C
> >  sol = solve(A*cos(theta)+B*sin(theta)==C, theta)
> > sol =
> >  -log((C + (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*i
> >  -log((C - (- A^2 - B^2 + C^2)^(1/2))/(A - B*i))*I
> 
> Yes. Those are the same solutions I obtained previously with 2011b.
> However,
> 
> Bruno used Mathematica to obtain four solutions in the form of 
> inverse trig functions.
> 
> Is there any way to use symbolic matlab to 
> 
> 1. Convert the log form to inv trig?
> 2. Obtain the other two solutions?

clear all, clc
syms a b c x

x = solve(a*cos(x)+b*sqrt(1-cos(x)^2)-c)

x =
 
  acos((a*c + b*(a^2 + b^2 - c^2)^(1/2))/(a^2 + b^2))
  acos((a*c - b*(a^2 + b^2 - c^2)^(1/2))/(a^2 + b^2))
 -acos((a*c + b*(a^2 + b^2 - c^2)^(1/2))/(a^2 + b^2))
 -acos((a*c - b*(a^2 + b^2 - c^2)^(1/2))/(a^2 + b^2))

Finally!

Hope this helps.
 
Greg
0
Reply heath (3882) 6/20/2012 5:25:09 AM

28 Replies
54 Views

(page loaded in 0.316 seconds)


Reply: