September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Numeric-error-propagation/00META.yaml
Normal file
1
Task/Numeric-error-propagation/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
enum VALUE, DELTA
|
||||
|
||||
type imprecise(object imp)
|
||||
return sequence(imp) and atom(imp[VALUE]) and atom(imp[DELTA])
|
||||
end type
|
||||
|
||||
function sqr(atom a)
|
||||
return a*a
|
||||
end function
|
||||
|
||||
function imprecise_add(imprecise a, b)
|
||||
atom delta = sqrt(sqr(a[DELTA]) + sqr(b[DELTA]))
|
||||
imprecise ret = {a[VALUE] + b[VALUE], delta}
|
||||
return ret
|
||||
end function
|
||||
|
||||
function imprecise_mul(imprecise a, b)
|
||||
atom delta = sqrt(sqr(a[VALUE]*b[DELTA]) + sqr(b[VALUE]*a[DELTA]))
|
||||
imprecise ret = {a[VALUE] * b[VALUE],delta}
|
||||
return ret
|
||||
end function
|
||||
|
||||
function imprecise_div(imprecise a, b)
|
||||
atom delta = sqrt(sqr(a[VALUE]*b[DELTA]) + sqr(b[VALUE]*a[DELTA]))/sqr(b[VALUE])
|
||||
imprecise ret = {a[VALUE] / b[VALUE], delta}
|
||||
return ret
|
||||
end function
|
||||
|
||||
function imprecise_pow(imprecise a, atom c)
|
||||
atom v = power(a[VALUE], c),
|
||||
delta = abs(v*c*a[DELTA]/a[VALUE])
|
||||
imprecise ret = {v,delta}
|
||||
return ret
|
||||
end function
|
||||
|
||||
function printImprecise(imprecise imp)
|
||||
return sprintf("%g+/-%g",imp)
|
||||
end function
|
||||
|
||||
imprecise x1 = {100, 1.1},
|
||||
y1 = {50, 1.2},
|
||||
x2 = {-200, 2.2},
|
||||
y2 = {-100, 2.3},
|
||||
tmp1, tmp2,
|
||||
d
|
||||
|
||||
tmp1 = imprecise_add(x1, x2)
|
||||
tmp1 = imprecise_pow(tmp1, 2)
|
||||
tmp2 = imprecise_add(y1, y2)
|
||||
tmp2 = imprecise_pow(tmp2, 2)
|
||||
d = imprecise_add(tmp1,tmp2)
|
||||
d = imprecise_pow(d, 0.5)
|
||||
printf(1,"Distance, d, between the following points :")
|
||||
printf(1,"\n( x1, y1) = ( %s, %s)",{printImprecise(x1),printImprecise(y1)})
|
||||
printf(1,"\n( x2, y2) = ( %s, %s)",{printImprecise(x2),printImprecise(y2)})
|
||||
printf(1,"\nis d = %s\n", {printImprecise(d)})
|
||||
Loading…
Add table
Add a link
Reference in a new issue