Mathematica Asked on June 6, 2021
My program recieves four inputs representing linkages in a 4-bars mechanism:
Then it has to find the Largest and Smallest linkage and evaluate its sum against the other two:
L+S<P+Q
where L is the largest linkage
S is the smallest
P & Q are the others.
My problem arises when there are two repeated linkages which happen to be max or min.
I want my program to do this without specifying which is the longest. So far I had to manually type what value to use. please help me.
Subscript[L, 1] = 0.15;
Subscript[L, 2] = 0.05;
Subscript[L, 3] = 0.15;
Subscript[L, 4] = 0.1;
linkages = Table[Subscript[L, i], {i, 1, 4}];
min = Min[linkages];
max = Max[linkages];
lizq = min + max;
Print["Are values unique?"]
DuplicateFreeQ[linkages]
dupl = Tally[linkages];
Print["Is Grasshoff condition satisfied?"]
middlelinks = Complement[linkages, {max, min}];
If[DuplicateFreeQ[eslabones], lizq < Total[middlelinks],
max + min < Total[middlelinks] + dupl[[1, 1]]]
ClearAll[grasshoffQ1, grasshoffQ2]
grasshoffQ1[lst : {a_, b_, c_, d_}] := Module[{sorted = Sort[lst]},
Total@sorted[[{1, -1}]] < Total@sorted[[{2, 3}]]]
grasshoffQ2[lst : {a_, b_, c_, d_}] := Module[{sorted = Sort[lst]},
Total@Differences[sorted, 2] < 0]
Examples:
SeedRandom[1]
lists = RandomInteger[10, {10, 4}];
Grid[Prepend[{"list", "Sort[list]", "minmax", "middlelinks",
"grasshoffQ1[list]", "grasshoffQ2[list]"}]@
Table[{i, Sort@i, MinMax@i, Sort[i][[{2, 3}]], grasshoffQ1@i, grasshoffQ2@i},
{i, lists}],
Dividers -> All]
Answered by kglr on June 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP