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.

7.2 Using Compiled Code in Maple • 293Example 2 The following example shows translation of a procedure to C.The defaulttype option sets the default type to integer, and the outputoption specifies that a string is to be returned. In this case, the output isassigned to variable s.> g := proc(x, y, z)> return x*y-y*z+x*z;> end proc:> s := CodeGeneration[‘C‘](g, defaulttype=integer, output=string);s := “int g (int x, int y, int z)\{\return(x * y - y * z + x * z);\}\”Example 3 The following example shows translation of a procedure toFortran. Because Fortran 77 is case-insensitive, the variable x is renamedto avoid a conflict with the variable X.> h := proc(X::numeric, x::Array(numeric, 5..7))> return X+x[5]+x[6]+x[7];> end proc:> CodeGeneration[Fortran](h);doubleprecision function h (cg, x)doubleprecision cgdoubleprecision x(5:7)h = cg + x(5) + x(6) + x(7)returnend7.2 Using Compiled Code in MapleThe following three calling methods are presented in this section.• Calling External Functions• Generating Wrappers• Customizing Wrappers

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

Saved successfully!

Ooh no, something went wrong!