MATLAB Answers

Solving for different thetas in an equation.

1 view (last 30 days)
Max Rivera
Max Rivera on 17 Jul 2021
Edited: John D'Errico on 18 Jul 2021
I was wondering if there was any way to determine multiple angles in an equation to make an equation true.
For example, an equation like: -4sin(theta1) - 6sin(theta2) + 5sin(theta2) = -3
or 4cos(theta1) + 6cos(theta2) + 5cos(theta3) = 12

Answers (2)

DGM
DGM on 17 Jul 2021
Edited: DGM on 18 Jul 2021
If you have a sufficient amount of information to describe the number of variables, then yes. If I make some assumptions:
% assuming that the equations given are not independent
% but constitute a system of equations
syms theta1 theta2
eq1 = -4*sin(theta1) - 6*sin(theta2) + 5*sin(theta2) == -3
eq1 = 
% assuming that theta3 was a typo
eq2 = 4*cos(theta1) + 6*cos(theta2) + 5*cos(theta2) == 12
eq2 = 
S = solve([eq1 eq2],[theta1 theta2])
S = struct with fields:
theta1: [2×1 sym] theta2: [2×1 sym]
S.theta1 % there are two solutions
ans = 
S.theta2
ans = 
If the assumptions that I made above do not apply, then refer to John's answer.

John D'Errico
John D'Errico on 18 Jul 2021
Edited: John D'Errico on 18 Jul 2021
You CANNOT solve for both theta1 and theta2 in a single equation like that. (I assume you meant a single equation, because you had the word OR in between the pair of equations you showed.) At best, you can solve for one variable in terms of the other. But effectively, what I will do here will allow you to generate infinintely many solution pairs, and do so trivially.
By the way, learn to use an asterisk to denote multiplication. Here is one of the equations you posed as an example:
syms theta1 theta2
E = -4*sin(theta1) - 6*sin(theta2) + 5*sin(theta2) == -3;
We can now simply solve for theta1, if we knew theta2. That is, we can do:
theta1 = solve(E,theta1)
theta1 = 
So there are two solutions. At least they may be real solutions.
fplot(theta1(1),[-pi,pi],'r-')
hold on
fplot(theta1(2),[-pi,pi],'b-')
legend('Solution1','Solution 2')
xlabel Theta2
ylabel Theta1
So the two solutions cross at a point. As long as you know theta2, you can compute TWO solutions for theta1. And then there would be infinitely more solutions at multiples of 2*pi up or down.
Essentially, you can pick ANY value for theta2, that gives you two primary solutions for the other. Any such equation will work the same way, although it may not be as trivial to solve. If you want to generate a list of solutions, then just pick a list for theta2...
theta2list = linspace(-pi,pi,100);
Now substitute those elements into the solution, computing a a pair of solutions for every theta2.
What I did above was little more complicated than if you had posed the problem
theta1 + 2*theta2 == 3
Surely you would know how to deal with that?

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!