ginac库基本代数运算

2020-10-11  本文已影响0人  一路向后

1.程序源码

#include <iostream>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;

int main()
{
        //定义未知数
        symbol x("x"), y("y");
        //定义代数式
        ex poly;

        //代数加法
        poly = x + y;

        cout << poly << endl;

        //代数减法
        poly = x - y;

        cout << poly << endl;

        //代数乘法
        poly = x * y;

        cout << poly << endl;

        //代数除法
        poly = x / y;

        cout << poly << endl;

        //代数乘方
        poly = pow(x, y);

        cout << poly << endl;

        //代数对数
        poly = log(y) / log(x);

        cout << poly << endl;

        //三角代数
        poly = sin(2*x);

        cout << poly << endl;

        return 0;
}

2.编译源码

$ g++ -o example example.c -lginac -lcln -I/usr/local/include -L/usr/local/lib64

3.运行结果

./example
x+y
x-y
x*y
x*y^(-1)
x^y
log(y)*log(x)^(-1)
sin(2*x)
上一篇下一篇

猜你喜欢

热点阅读