Brute force combination of two vectors. Yet, the combination only gets written in a matrix if it fulfils two constraints.

조회 수: 1 (최근 30일)
I have two vectors:
L_1=[30:10:500];
L_2=[30:10:500];
and two values that are known:
a=250;
b=482;
These vectors are now of the same size, but this is not always the case. Thus, I would like to create a matrix (2 columns) that has every possible combination L_1,L_2 that fulfils the following constraints.
L_1< (a/theta_a); AND L_1< (b/theta_b);
The values theta_a and theta_b are calculated through on behalf of the values L_1 and L_2 with the following formula:
Theta_a=acosd((a^2+L_1^2-L_2^2)/(2*a*L_1);
Theta_b=acosd((b^2+L_1^2-L_2^2)/(2*b*L_1);
It would be great if the computational time can be reduced by an efficient script.
Thank you in advance.
  댓글 수: 1
Ameer Hamza
Ameer Hamza 2020년 3월 9일
For the values of L_1 and L_2, a and b you gave, the function acosd can return complex value. The domain of acosd is -1 to 1 for real-valued output. But the input of acosd
(a^2+L_1^2-L_2^2)/(2*a*L_1)
can take any value beyong -1 to 1. How will you do comparison in that case.

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 9일
편집: Ameer Hamza 2020년 3월 9일
L_1=30:1:500;
L_2=30:1:500;
a=250;
b=482;
combinations = combvec(L_1, L_2)';
Theta_a=acos((a^2+combinations(:,1).^2-combinations(:,2).^2) ...
./(2*a*combinations(:,1)));
Theta_b=acos((b^2+combinations(:,1).^2-combinations(:,2).^2) ...
./(2*b*combinations(:,1)));
mask = imag(Theta_a) == 0 & imag(Theta_b) == 0; % only keep rows where both angles are real
mask = mask & (combinations(:,1) < a./Theta_a) & (combinations(:,1) < b./Theta_b);
final_combinations = combinations(mask, :);
  댓글 수: 2
Abdelmajid Ben yahya
Abdelmajid Ben yahya 2020년 3월 9일
the first assumptions is not correct, as the formua is the derivation of the cosine rule.
These constraints are made to erase certain mechanical configurations, within a physical crank-shaft mechanism.
I attached some drawings to explainthe idea.
the first two drawings (top) show the mechanism, while the drawings underneath show the derivation of the constraints.
So, i think that the made assumptions can be rejected.
Ameer Hamza
Ameer Hamza 2020년 3월 9일
Ok, your formula is correct. I think it produces an imaginary number in some cases because it is impossible to create a real triangle for some combinations of L_1, L_2, a, and b. I corrected the code and added another condition that both angles should be real.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by