Numeric error propagation: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added whitespace, used a template for the output section.)
Line 2,329: Line 2,329:
parse var ax ax '±' axe; parse var bx bx '±' bxE /* " err " Ax and Bx.*/
parse var ax ax '±' axe; parse var bx bx '±' bxE /* " err " Ax and Bx.*/
parse var ay ay '±' aye; parse var by by '±' byE /* " " " Ay " By.*/
parse var ay ay '±' aye; parse var by by '±' byE /* " " " Ay " By.*/
if axE=='' then axE=0; if bxE=="" then bxE=0; /*No error? Then use default.*/
if axE=='' then axE= 0; if bxE=="" then bxE= 0 /*No error? Then use default.*/
if ayE=='' then ayE=0; if byE=="" then byE=0; /* " " " " " */
if ayE=='' then ayE= 0; if byE=="" then byE= 0 /* " " " " " */
say ' A point (x,y)= ' ax "±" axE', ' ay "±" ayE /*display A point (with err)*/
say ' A point (x,y)= ' ax "±" axE', ' ay "±" ayE /*display A point (with err)*/
say ' B point (x.y)= ' bx "±" bxE', ' by "±" byE /* " B " " " */
say ' B point (x.y)= ' bx "±" bxE', ' by "±" byE /* " B " " " */
say /*blank line for the eyeballs.*/
say /*blank line for the eyeballs.*/
dx=ax-bx; dxE=sqrt(axE**2 + bxE**2); xe=#(dx, 2, dxE) /*compute X distances (& err)*/
dx= ax-bx; dxE= sqrt(axE**2 + bxE**2); xe= #(dx, 2, dxE) /*compute X distances (& err)*/
dy=ay-by; dyE=sqrt(ayE**2 + byE**2); ye=#(dy, 2, dyE) /* " Y " " " */
dy= ay-by; dyE= sqrt(ayE**2 + byE**2); ye= #(dy, 2, dyE) /* " Y " " " */
D=sqrt(dx**2 + dy**2) /*compute the 2D distance. */
D= sqrt(dx**2 + dy**2) /*compute the 2D distance. */
say 'distance=' D "±" #(D**2, .5, sqrt(xE**2 + yE**2)) /*display " " " */
say 'distance=' D "±" #(D**2, .5, sqrt(xE**2 + yE**2)) /*display " " " */
exit /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
#: procedure; arg x,p,e; if p=.5 then z=1/sqrt(abs(x)); else z=abs(x)**(p-1); return p*e*z
#: procedure; arg x,p,e; if p=.5 then z=1/sqrt(abs(x)); else z=abs(x)**(p-1); return p*e*z
Line 2,346: Line 2,346:
m.=9; do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
m.=9; do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
numeric digits d; return g/1</lang>
numeric digits d; return g/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
'''output''' &nbsp; when using the default inputs:
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); numeric digits; h=d+6
numeric form; parse value format(x,2,1,,0) 'E0' with g "E" _ .; g= g * .5'e'_ % 2
m.= 9; do j=0 while h>9; m.j= h; h= h%2+1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g)*.5; end /*k*/
numeric digits d; return g/1</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
A point (x,y)= 100 ± 1.1, 50 ± 1.2
A point (x,y)= 100 ± 1.1, 50 ± 1.2