11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.2 Hardware Floating-Point Numbers • 203Example The following procedure calculates the polynomial 2+5x+4x 2 .> p := proc(x)> local a, i;> a := array(0..2);> a[0] := 2;> a[1] := 5;> a[2] := 4;> sum( a[i]*x^i, i=0..2 );> end proc:> p(x);2 + 5 x + 4 x 2If you intend to enclose p in a call to evalhf, you cannot define the localarray a using array(1..3, [2,5,4]) because lists are not supportedin evalhf. You can, however, enclose p in a call to evalhf if the parameterx is a number.> evalhf(p(5.6));155.439999999999997You can also pass an array of numbers as a parameter inside a call toevalhf.Example The following procedure calculates the determinant of a 2 × 2matrix. The (2,2) entry in the array a is unassigned.> det := proc(a::array(2))> a[1,1] * a[2,2] - a[1,2] * a[2,1];> end proc:> a := array( [[2/3, 3/4], [4/9]] );> det(a);⎡2⎢ 3a := ⎣3449 a 2, 2⎤⎥⎦

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!