Particle swarm optimization: Difference between revisions

m
→‎{{header|REXX}}: increased the number of decimal digits for pi.
m (→‎{{header|REXX}}: changed use of single and double quote characters.)
m (→‎{{header|REXX}}: increased the number of decimal digits for pi.)
Line 416:
Classic REXX doesn't have a   '''sine'''   function, so a RYO version is included here.
 
The numeric precision is only limited to the number of decimal digits defined in the &nbsp; <big> '''pi''' </big> &nbsp; variable &nbsp; (in this case, &nbsp; '''100118''').
 
This REXX version supports the specifying of &nbsp; '''X''', &nbsp; '''Y''', &nbsp; and &nbsp; '''D''', &nbsp; as well as the number of particles, &nbsp; and the number of decimal digits to be displayed.
Line 424:
Note that REXX used decimal floating point, not binary.
<lang rexx>/*REXX program calculates Particle Swarm Optimization as it migrates through a solution.*/
numeric digits length(pi()) - 1 /*sDigs: is the # of displayed digits.*/
parse arg x y d #part sDigs . /*obtain optional arguments from the CL*/
if x=='' | x=="," then x= -0.5 /*Not specified? Then use the default.*/
Line 453:
f: procedure: parse arg a,b; return sin(a+b) + (a-b)**2 - 1.5*a + 2.5*b + 1
fmt: parse arg ?; ?=format(?,,sDigs); L=length(?); if pos(.,?)\==0 then ?=strip(strip(?,'T',0),"T",.); return left(?,L)
pi: pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282307; return pi
pi: pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068; return pi
r2r: return arg(1) // (pi()*2) /*normalize radians ───► a unit circle.*/
sin: procedure; parse arg x; x=r2r(x); numeric fuzz 5; z=x; _=x; q=x*x; do k=2 by 2 until p=z; p=z; _=-_*q/(k*(k+1)); z=z+_; end; return z</lang>