Модератор: Модераторы
> > >The simplest (and slowest) thing might be to start maxima in batch
> > >mode everytime you need to compute something, make it write the result to a
> > >file and quit.
> >
> > That sounds like a good idea, how do I start maxima in batch mode?
>
> well, from your C++ program (on solaris, or just any Unix, I guess) you can do
> roughly something like
>
> #include <stdlib.h>
> ...
> // write stuff to foo
>
> system("maxima <foo >bar"); // call maxima; hope it doesn't hang...
>
> // read bar
> ....
>
> This is of course slow (not only file I/O, but starting up maxima),
> but would give you a proof of the concept,
> so to speak:)
Here's two (not very exciting) examples. But for
non-programmers (like me!) calling Maxima with
a "system" command works well in c++, tcl/tk,
perl, quick and dirty cgi-scripting, etc.
///////////////////////////////////
// maxima_c2.cpp
#include <stdlib.h>
#include <iostream.h>
int main(int argc, char *argv[])
{
cout << "Call One Line Maxima Command from C++" << endl;
for (int i = 1; i < argc; i++)
cout << argv[i] << endl; //print args, if any
system("echo 'factor((x^2-1));' | maxima > test");
system("grep D1 test");
return 0;
}
///////////////////////////////////
# compile with
g++ maxima_c.cpp -o maxima_c
# run
./maxima_c "x^2 -1 = "
# output
Call One Line Maxima Command from C++
x^2 - 1 =
(D1) (x - 1) (x + 1)
///////////////////////////////////
// maxima_c2.cpp
// put the following commands in a file called
// "file.mac", call with "batch(file);"
//
// factor((y^2-x^2));
// expand(%);
// depends(y,x);
// diff(x^2-y^2=0,x);
#include <stdlib.h>
#include <iostream.h>
int main(int argc, char *argv[])
{
cout << "Call Maxima Batch Commands from C++" << endl;
for (int i = 1; i < argc; i++)
cout << argv[i] << endl;
system("echo 'batch(file);' | maxima > test");
system("sed -n 10~1p test");
return 0;
}
///////////////////////////////////
# compile with
g++ maxima_c2.cpp -o maxima_c2
# run
./maxima_c2 "several commands ..."
# output
Call Maxima Batch Commands from C++
several commands
2 2
(C2) FACTOR(y - x )
(D2) (y - x) (y + x)
(C3)
(C3) EXPAND(%)
2 2
(D3) y - x
(C4)
(C4) DEPENDS(y, x)
(D4) [y(x)]
(C5)
2 2
(C5) DIFF(x - y = 0, x)
dy
(D5) 2 x - 2 y -- = 0
dx
L. Prevett
Mathematics Instructor
Cochise College, Sierra Vista, AZ, US
prevettl@cochise.cc.az.us
maxima --very-quiet --batch-string="sin(%pi/4)"
maxima --very-quiet --batch=proga.mac
daesher писал(а):Пробовал. Вот парочка модулей (sets и mystr нужны для всего проекта, но модули на них завязаны, поэтому прикладываю)
Вернуться в Free Pascal Compiler
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 60