Trying to solve equations within ranges
2 views (last 30 days)
Show older comments
Sean Hart
on 9 Nov 2021
Answered: Sulaymon Eshkabilov
on 9 Nov 2021
I'm trying to set up a problem. I have two equations:
cos(q1) + cos(q1 + q2) = [x1:x2] and sin(q1) + sin(q1 + q2) = [y1, y2] where x1,x2 are endpoints of horizontal ranges and y1, y2 are endpoints of vertical ranges. All are between -2 and 2. I want to find ranges of angles of q1 and q2 that'll work within these parameters. and x2 - x1 does not equal y2 -y1.
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 9 Nov 2021
One of the viable solutions is to use symbolic math: syms and solve.
clearvars; clc
x1=-2; x2=2;
y1=-2.1; y2=2.1;
x = x1:0.1:x2;
y = linspace(y1, y2, length(x));
syms q1 q2
Angle1 = zeros(length(x), 2);
Angle2 = Angle1;
for ii = 1:numel(x)
Eq1 = cos(q1) + cos(q1 + q2) == x(ii);
Eq2 = sin(q1) + sin(q1 + q2) == y(ii);
SOL = solve(Eq1, Eq2);
Q1=[double(SOL.q1(1,1)), double(SOL.q1(2,1))];
Q2=[double(SOL.q2(1,1)), double(SOL.q2(2,1))];
Angle1(ii, 1) =Q1(1); Angle1(ii, 2) =Q1(2);
Angle2(ii, 1) =Q2(1); Angle2(ii, 2) =Q2(2);
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!