Trying to solve equations within ranges
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Sulaymon Eshkabilov
2021년 11월 9일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!