COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Problem in solving an equation symbolically

• Email
• 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 (228) 6/9/2012 9:22:07 AM

See related articles to this posting

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

"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 (7942) 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 (228) 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 (3990) 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 (3990) 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 (228) 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 (6403) 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 (228) 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 (6403) 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 (3990) 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 (3990) 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 (6403) 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 (3990) 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 (834) 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

"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 (3990) 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 (6403) 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

Greg

 0
Reply heath (3990) 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) }

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

Hope this helps.

Greg

 0
Reply heath (3990) 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 (3990) 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

"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 (6403) 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 (3990) 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 (6403) 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 (3990) 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 (3990) 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

"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 (3990) 6/20/2012 5:25:09 AM

28 Replies
65 Views

Similar Articles

12/12/2013 12:15:22 PM
[PageSpeed]

Similar Artilces:

problem with solving symbolic equation
i wanna find the cross points of 2 circles with center point and radius which changed each run. i define the following ----------------------------------------------------------- syms x y x_center y_center r eq=(x-x_center)^2+(y-y_center)^2-r^2; x_center=X(1); y_center=Y(1); r=R(1); eq1=subs(eq); x_center=X(2); y_center=Y(2); r=R(2); eq2=subs(eq); ----------------------------------------------------------- and to solve i use ----------------------------------------------------------- [x12,y12]=solve(eq1,eq2); x12=eval(x12); y12=eval(y12); ---------------------------------...

Problem solving stiff differential equations
Hello everybody, I'm working on a model based on a system of differential equations. I'm solving this system with the ode-solvers (mostly ode23s) and the results are pretty accurate. The problem is that several steep transitions (upward direction) occur in the solution to the differential equations and there seems to be a bad convergence in the region around that transition, even although I'm using a stiff solver. I've already tried the suggestions in Matlab help, like splitting it up in more intervals and using another solver. Finding the solution already takes a lot of time...

solving transcendental symbolic equation in complex plane
I have the following problem. Given a function Phi = 1+int(exp(i*lambda*t),t,0,1) I need to find the zeros of such function. The series of zeros {lambda_k} is a series of complex numbers. Is there any way I could find the zeros? When using "solve" Matlab gives the following: >> Phi = 1+int(exp(i*lambda*t),t,0,1) Phi = 1-i/lambda*(exp(i*lambda)-1) >> solve(Phi) ans = 0 Thank you. ...

solving problem with four equations and four unknown variables
Dear Fellows, I have four unknowns tau1,tau2, p1 and p2, all of them are probabilities and are in the range of 0 to 1. The four equations are below: tau1 = f(p1,p2) tau2 = f(p1,p2) p1 = f(tau1) p2 = f(tau1,tau2). These unknowns are coupled in each other and cannot be solved using fzero(). Can someone give me a hint to solveit, especially if someone let me know how to use fsolve() function in this situation. Thanks in advance. -bilal On 8 Okt., 10:59, Bilal <bilalci...@googlemail.com> wrote: > Dear Fellows, > > I have four unknowns tau1,tau2, p1 and p2, all o...

Solve exact problem with approx solution, or solve approx problem with exact solution
Tukey (inventor of FFT) thinks that an approximate solution of the exact problem is often more useful than the exact solution of an approximate problem. I find it hard to argue which one is more important or useful. Once you believe in one of them, your belief will lead your research style to either algorithm-centered or model-construction-centered. Anybody wants to elaborate on either of these two views? b83503104@yahoo.com wrote: > Tukey (inventor of FFT) thinks that an approximate solution of the > exact problem is often more useful than the exact solution of an > approximate ...

Solving nonlinear equation system with lsqnonlin
Hello all, I working with the nonlinear solver lsqnonlin in order to solve a nonlinear equation system f(x)-g(x) = 0. There two different types of equations in this system, ie. f1(x)-g1(x) and f2(x)-g2(x). The absolute values of the f and g are very different for these two types. The first ist about 1 and the other in the range of 1*10-6. This means that although I have quite good starting values, the values of the two equations f1(x0)-g1(x0) and f2(x0)-g2(x0) are extremly differing by many orders of magnitude. Because of that, lsqnonlin is only optimizing the first equations with the larger ...

solve equation
hi, i found an easy and quick way to solve equation, but i always get following error: K>> mue = fzero(inline('mue*tan(alpha_tpp)+CT/(2*sqrt(mue.^2+lambda.^2))-lambda= 0'),18,[],alpha_tpp,lambda,CT); Warning: Cannot determine from calling sequence whether to use new or grandfathered FZERO function. Using new; if call was grandfathered FZERO syntax, this may give unexpected results. > In D:\Programme\matlabR12\toolbox\matlab\funfun\fzero.m (parse_call) at line 412 In D:\Programme\matlabR12\toolbox\matlab\funfun\fzero.m at line 103 In D:\Studienarbeit\aktuelle Studienarb...

How to solve these equations?
a =13.9497; b = 1.8350e+003; c = 140.4557; d =5.8077e-009; k1_2 =9.3378e-007; k2_2 =6.6098e-010; syms x y f1 = (b*d-k1_2*a) + (d+b+k1_2)*x + (b-d)*y + x^2 -y^2; f2 = (c*d-k2_2*b) + (c-k2_2)*x + (c+d+k2_2)*y + x*y + y^2; %-------------------------------------------------------------- [x,y]=solve(f1,f2); What I got are not real numbers at all. But I'm sure these equations should have real number solutions based on their physical meaning. What have I missed? Thank you. "Liqing " <liqingj@gmail.com> wrote in message <froq97$n0c$1@fred....

symbolic solve
Hello guys I need to symbolic solve this sistem x=(a*(1-p1)*(p2*y)+(b*g1))/(a*(1-p1)+b) y=(a*(1-p2)*(p1*x)+b*g2)/a*(1-p2)+b) I use this command Is it correct? solve('x=(a*(1-p1)*(p2*y)+(b*g1))/(a*(1-p1)+b),y=... (a*(1-p2)*(p1*x)+b*g2)/a*(1-p2)+b') Thanks for your help stefano wrote: > > > Hello guys I need to symbolic solve this sistem > x=(a*(1-p1)*(p2*y)+(b*g1))/(a*(1-p1)+b) > y=(a*(1-p2)*(p1*x)+b*g2)/a*(1-p2)+b) > I use this command Is it correct? > solve('x=(a*(1-p1)*(p2*y)+(b*g1))/(a*(1-p1)+b),y=... > (a*(1-p2)*(p1*x)+b*g2)/a*(1-p2)+b') > Thanks...

Problem with Solve
I have a bizarre Problem. In trying to run this standard economics maximization problem Mathematica runs ad infinitum. Same if instead of Solve I use NSolve. Same if I split up the problem in doing first the partial derivatives etc. It is definitely a Solve/NSolve problem, but I can't believe that it is not able to do this numerical stories on such a standard problem with so well-behaved functions. Foc[f_,x_]:=Map[(D[f,#]==0)&,x] Parameters: L=80; K=80; \alpha1= 3/4; \alpha2 = 1- \alpha1; \beta1 = 1/3; \beta2=1 - \beta2; Q1 = L1^\alpha1 K1^\alpha2 Q2 = (L-L1)^\...

How is this problems solved in praxis?
When designing a compiler automatically parallelizing programs after data-flow analysis, it would be desirable if the number of communications (or thread switches when run on fewer processors than threads) between threads would be minimized. How is this problem solved in praxis (if at all)? Best regards, Henning ...

solving an equation in matlab
Hi, I wanted to know if there were any inbuilt commands in matlab to solve the equation of the form f(x)=0 numerically. The function f(x) is composed of user written functions. I would really appreciate any help of this as I need it for some urgent work. Thanks. In article <ef26062.-1@webx.raydaftYaTP>, "Apoorva Shende" <apoorvashende@indiatimes.com> wrote: > Hi, I wanted to know if there were any inbuilt commands in matlab to > solve the equation of the form f(x)=0 numerically. The function f(x) > is composed of user written functions. I would really apprecia...

Symbolic Reference Problem
Hi all, I previously had some repetitive code that I wanted to simplify. The code was of the following nature: #!/usr/bin/perl while (<>){ if (/Display vara/){chomp($vara = <>)} if (/Display varb/){chomp($varb = <>)} .. more of the same repeated .. .. .. I tried to simplify this with while (<>){ @vars = (vara, varb); foreach $variable (@vars){ if (/Display$variable/){ chomp(variable = <>); } } } However, when I use strict, I get an error because I am using a symbolic reference. Does anyone know an easier way of...

HP Solve problem
I have two problems I hope someone can help with. 1. I'm having trouble getting the numeric solver to work on this problem. I have these variables defined in a directory: 'w' -- 1. 'wn' -- 1. 's' -- 'i*w" 'Lo1' -- 'wn/(s+wn)' 'MAG' -- 'Gdb=20.*LOG(ABS(Lo1))' I select 'MAG' to solve. In the solver, I enter a value of 1. for both 'w' and 'wn'. When I try to solve for 'GdB', the solver says "Bad Guess(es)". If I change 'MAG' to 'GdB=20.*LOG(ABS(wn/(i*w+wn))' (...

solving nonlinear equations
Ok I've got this equation that is of the general form A=B*C^D, where B and C have the variable I want to solve for in them, C actually has two variables in it and I didn't display them for sake of simplicity. D is a constant which is expressed in terms of a variable which is also present in C. I am looking for a closed form solution to this problem although one may not actually exist. Does anyone know any good methods for solving nonlinear equations in MATLAB? I have access to versions 6.1 and 6.5 if that makes any difference. Matt All we know from your description is that A = B(x)...

Matrix Equation solving
Please help me to solve the equation A'pA-p = -I A - 3x3 matrix p - 3x3 unknown symetric matrix I - identity matrix "shameer koya" <assigmenteee@yahoo.co.in> wrote in message <fhe92r$m23$1@fred.mathworks.com>... > Please help me to solve the equation > > A'pA-p = -I > > A - 3x3 matrix > p - 3x3 unknown symetric matrix > I - identity matrix ---------- This is, after all, a set of nine linear equations in the nine unknown elements of p, and can therefore be solved by matlab using standard techniques with the backslash operator, with p te...

Solving differential equations?
Following are the two differential equations: dx/dr = [a*(1-x^2+y^2)]/{r(r-1)]^(1/2)-2b*[r/(r-1)]^(1/2)*x - 0.0152*[r/(r-1)]^(1/2)*xy dy/dr = -2a*xy/[r(r-1)]-2b*[r/(r-1)]^(1/2)*y + 0.0076*[r/(r-1)]^(1/2) *(1+x^2-y^2) with initial conditions: x(5.67)= - {a[br + (b^2*r^2 + a^2 + 0.000058*r^2)^(1/2)]}/(a^2 + 0.000058*r^2) y(5.67)= -{0.0076*r[br + (b^2*r^2 + a^2 + 0.000058*r^2)^(1/2)]}/(a^2 + 0.000058*r^2) where r is the independent variable, x and y are dependent variables to be solved, and a and b are constant parameters. It would be a great help to me if someone could give ...

Solve equation problme
Hi all Does Anyone know how to solve The Kronig-Penney model using matlab? I try to use 'solve' function and found it is difficult. Any suggestion will be appreciated. Cheers, B lixiaoyao wrote: > > > Hi all > Does Anyone know how to solve The Kronig-Penney model using > matlab? I > try to use 'solve' function and found it is difficult. Any > suggestion > will be appreciated. > Cheers, > B > > This paper has some ML code for the KP model: <http://www.imit.kth.se/info/SSD/KMF/2B1711/KP_lab.pdf> Scott ...

symbolic substitution problem
Does anyone have idea why the following behaves as it behaves: subs(cos(alpha)+sin(alpha),{cos(alpha),sin(alpha)},{1,alpha}) ans = cos(sin(alpha))+sin(sin(alpha)) % changed order of args syms alpha subs(cos(alpha)+sin(alpha),{cos(alpha),sin(alpha)},{1,alpha},0) ans = cos(alpha)+sin(alpha) % i.e. not substitution % BUT when separated: subs(cos(alpha)+sin(alpha),{cos(alpha)},{1},0) ans = 1+sin(alpha) subs(ans,{sin(alpha)},{alpha},0) ans = 1+alpha Brano ...

solve equations set
We known: &#955;=441.6×&#12310;10&#12311;^(-6)&#65292;e= 1/1200,u=0.00283498,R=127.35 how to solve the equations set as following using Matlab: -sin&#952;_1+sin&#952;_2=&#955;/e ((cos^2 &#952;_1)/r_1 -(cos&#952;_1)/R)-((cos^2 &#952;_2)/r_2 -(cos&#952;_2)/R)=&#955;/e u (sin&#952;_1)/r_1 ((cos^2 &#952;_1)/r_1 -(cos&#952;_1)/R)-(sin&#952;_2)/r_2 ((cos^2 &#952;_2)/r_2 -(cos&#952;_2)/R)=0 (1/r_1 -(cos&#952;_1)/R)-(1/r_2 -(cos&#952;_2)/R)=0 it's important to my subject,so if someone can solve the prob...