# Thread Subject: Problem in solving an equation symbolically

 Subject: Problem in solving an equation symbolically From: pietro Date: 9 Jun, 2012 09:22:07 Message: 1 of 29 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
 Subject: Problem in solving an equation symbolically From: Nasser M. Abbasi Date: 9 Jun, 2012 09:56:00 Message: 2 of 29 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
 Subject: Problem in solving an equation symbolically From: John D'Errico Date: 9 Jun, 2012 10:28:07 Message: 3 of 29 "pietro " wrote in message ... > 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
 Subject: Problem in solving an equation symbolically From: pietro Date: 9 Jun, 2012 13:13:08 Message: 4 of 29 "John D'Errico" wrote in message ... > "pietro " wrote in message ... > > 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.
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 9 Jun, 2012 18:55:07 Message: 5 of 29 "pietro " wrote in message ... > 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 10 Jun, 2012 01:31:09 Message: 6 of 29 "Greg Heath" wrote in message ... > "pietro " wrote in message > ... > > 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
 Subject: Problem in solving an equation symbolically From: pietro Date: 10 Jun, 2012 11:10:08 Message: 7 of 29 "Greg Heath" wrote in message ... > "Greg Heath" wrote in message ... > > "pietro " wrote in message > > ... > > > 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
 Subject: Problem in solving an equation symbolically From: Bruno Luong Date: 10 Jun, 2012 11:30:09 Message: 8 of 29 "pietro " 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
 Subject: Problem in solving an equation symbolically From: pietro Date: 10 Jun, 2012 11:50:08 Message: 9 of 29 "Bruno Luong" wrote in message ... > "pietro " 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...
 Subject: Problem in solving an equation symbolically From: Bruno Luong Date: 10 Jun, 2012 15:42:07 Message: 10 of 29 "pietro " wrote in message ... > "Bruno Luong" wrote in message ... > > "pietro " 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 10 Jun, 2012 23:09:06 Message: 11 of 29 "pietro " wrote in message ... > "Greg Heath" wrote in message ... > > "Greg Heath" wrote in message ... > > > "pietro " wrote in message > > > ... > > > > 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 10 Jun, 2012 23:10:07 Message: 12 of 29 "pietro " wrote in message ... > "Greg Heath" wrote in message ... > > "Greg Heath" wrote in message ... > > > "pietro " wrote in message > > > ... > > > > 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
 Subject: Problem in solving an equation symbolically From: Bruno Luong Date: 11 Jun, 2012 00:58:06 Message: 13 of 29 "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 11 Jun, 2012 03:06:07 Message: 14 of 29 "Bruno Luong" wrote in message ... > "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Loren Shure Date: 11 Jun, 2012 08:37:16 Message: 15 of 29 "pietro " 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/
 Subject: Problem in solving an equation symbolically From: Nasser M. Abbasi Date: 11 Jun, 2012 09:35:18 Message: 16 of 29 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 11 Jun, 2012 16:40:07 Message: 17 of 29 "Loren Shure" wrote in message ... > > "pietro " 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
 Subject: Problem in solving an equation symbolically From: Bruno Luong Date: 11 Jun, 2012 18:20:08 Message: 18 of 29 "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 11 Jun, 2012 22:23:06 Message: 19 of 29 "Bruno Luong" wrote in message ... > "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 11 Jun, 2012 22:53:06 Message: 20 of 29 "Nasser M. Abbasi" wrote in message ... > 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 11 Jun, 2012 23:32:07 Message: 21 of 29 "Greg Heath" wrote in message ... > "Loren Shure" wrote in message ... > > > > "pietro " 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
 Subject: Problem in solving an equation symbolically From: Nasser M. Abbasi Date: 12 Jun, 2012 01:08:22 Message: 22 of 29 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
 Subject: Problem in solving an equation symbolically From: Bruno Luong Date: 12 Jun, 2012 07:38:07 Message: 23 of 29 "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 12 Jun, 2012 10:46:07 Message: 24 of 29 "Bruno Luong" wrote in message ... > "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Bruno Luong Date: 13 Jun, 2012 07:15:07 Message: 25 of 29 "Greg Heath" wrote in message ... > "Bruno Luong" wrote in message ... > > "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 13 Jun, 2012 14:12:09 Message: 26 of 29 "Bruno Luong" wrote in message ... > "Greg Heath" wrote in message ... > > "Bruno Luong" wrote in message ... > > > "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 13 Jun, 2012 15:48:07 Message: 27 of 29 "Greg Heath" wrote in message ... > "Bruno Luong" wrote in message ... > > "Greg Heath" wrote in message ... > > > "Bruno Luong" wrote in message ... > > > > "Greg Heath" 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
 Subject: Problem in solving an equation symbolically From: Christopher Creutzig Date: 14 Jun, 2012 15:09:08 Message: 28 of 29 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
 Subject: Problem in solving an equation symbolically From: Greg Heath Date: 20 Jun, 2012 05:25:09 Message: 29 of 29 "Greg Heath" wrote in message ... > "Loren Shure" wrote in message ... > > > > "pietro " 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

Separated by commas
Ex.: root locus, bode

### 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.