我的回复(2014-5-27 09:19):Here is a very simple C program showing how to connect to Maple and call a basic Maple command. The program calls Maple's diff routine via the OpenMaple API to compute the derivative of
sin(cos(x))
symbolically and evaluate it at
x = 3
.
#include <stdio.h>
#include <stdlib.h>
/* OpenMaple routines are defined here */
#include "maplec.h"
/* Callback used for directing result output */
static void M_DECL textCallBack( void *data, int tag, char *output )
{
printf("%s\n", output);
}
int main( int argc, char *argv[] )
{
char err[2048];
/*
* Maple kernel vector - used to start and make calls to Maple.
* All OpenMaple function calls take kv as an argument.
*/
MKernelVector kv;
MCallBackVectorDesc cb = { textCallBack,
0, /* errorCallBack not used */
0, /* statusCallBack not used */
0, /* readLineCallBack not used */
0, /* redirectCallBack not used */
0, /* streamCallBack not used */
0, /* queryInterrupt not used */
0 /* callBackCallBack not used */
};
/*
* ALGEB is the C data type for representing Maple
* data structures
*/
ALGEB r, l;
/*
* Compute the derivative of sin(cos(x)).
* Output goes through the textCallBack() procedure.
*/
printf( "Compute a derivative: \n\t" );
r = EvalMapleStatement( kv, "diff(sin(cos(x)),x);" );
/* Evaluate the derivative at x = 3 */
MapleAssign(kv,
ToMapleName( kv, "x", TRUE ),
ToMapleInteger( kv, 3 ));
r = MapleEval( kv, r );
MapleALGEB_Printf( kv, "\nThe derivative at x=3 is: %a\n", r );
res := ssystem(cmpcmd);
printf("%s\n", res[2]);
res := ssystem(lnkcmd);
printf("%s\n", res[2]);
NULL;
end proc:
C_OPEN_MAPLE_EXE := "COpenMaple.exe";
C_OPEN_MAPLE_SRC := "COpenMaple";
Compile(C_OPEN_MAPLE_SRC, C_OPEN_MAPLE_EXE);
res := ssystem("COpenMaple"):
printf("%s", res[2]);
我的回复(2014-5-27 09:18):Here is a very simple C program showing how to connect to Maple and call a basic Maple command. The program calls Maple's diff routine via the OpenMaple API to compute the derivative of
sin(cos(x))
symbolically and evaluate it at
x = 3
.
#include <stdio.h>
#include <stdlib.h>
/* OpenMaple routines are defined here */
#include "maplec.h"
/* Callback used for directing result output */
static void M_DECL textCallBack( void *data, int tag, char *output )
{
printf("%s\n", output);
}
int main( int argc, char *argv[] )
{
char err[2048];
/*
* Maple kernel vector - used to start and make calls to Maple.
* All OpenMaple function calls take kv as an argument.
*/
MKernelVector kv;
MCallBackVectorDesc cb = { textCallBack,
0, /* errorCallBack not used */
0, /* statusCallBack not used */
0, /* readLineCallBack not used */
0, /* redirectCallBack not used */
0, /* streamCallBack not used */
0, /* queryInterrupt not used */
0 /* callBackCallBack not used */
};
/*
* ALGEB is the C data type for representing Maple
* data structures
*/
ALGEB r, l;
/*
* Compute the derivative of sin(cos(x)).
* Output goes through the textCallBack() procedure.
*/
printf( "Compute a derivative: \n\t" );
r = EvalMapleStatement( kv, "diff(sin(cos(x)),x);" );
/* Evaluate the derivative at x = 3 */
MapleAssign(kv,
ToMapleName( kv, "x", TRUE ),
ToMapleInteger( kv, 3 ));
r = MapleEval( kv, r );
MapleALGEB_Printf( kv, "\nThe derivative at x=3 is: %a\n", r );