Logo Search packages:      
Sourcecode: cantor version File versions  Download package

maximaextensions.cpp

/*
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA  02110-1301, USA.

    ---
    Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
 */

#include "maximaextensions.h"
#include <QStringList>
#include <klocale.h>

#define MAXIMA_EXTENSION_CONSTRUCTORS(name) Maxima##name##Extension::Maxima##name##Extension(QObject* parent) : name##Extension(parent) {} \
                                     Maxima##name##Extension::~Maxima##name##Extension() {}

//History Extension
MAXIMA_EXTENSION_CONSTRUCTORS(History)

00031 QString MaximaHistoryExtension::lastResult()
{
    return "%";
}

//Script
MAXIMA_EXTENSION_CONSTRUCTORS(Script)

00039 QString MaximaScriptExtension::runExternalScript(const QString& file)
{
    return QString("batch(\"%1\")$").arg(file);
}

00044 QString MaximaScriptExtension::scriptFileFilter()
{
    return i18n("*.mac|Maxima batch File");
}

00049 QString MaximaScriptExtension::commentStartingSequence()
{
    return "/* ";
}

00054 QString MaximaScriptExtension::commentEndingSequence()
{
    return " */";
}

//CAS Extension
MAXIMA_EXTENSION_CONSTRUCTORS(CAS)

00062 QString MaximaCASExtension::solve(const QStringList& equations, const QStringList& variables)
{
    QString eqstr=QString("[%1]").arg(equations.join(","));

    QString variablestr=QString("[%1]").arg(variables.join(","));

    return QString("solve(%1,%2);").arg(eqstr, variablestr);
}

00071 QString MaximaCASExtension::simplify(const QString& expression)
{
    return QString("simplify(%1);").arg(expression);
}

00076 QString MaximaCASExtension::expand(const QString& expression)
{
    return QString("expand(%1);").arg(expression);
}

//Calculus Extension
MAXIMA_EXTENSION_CONSTRUCTORS(Calculus)

00084 QString MaximaCalculusExtension::limit(const QString& expression, const QString& variable, const QString& limit)
{
    return QString("limit(%1, %2=%3);").arg(expression, variable, limit);
}

00089 QString MaximaCalculusExtension::differentiate(const QString& function,const QString& variable, int times)
{
    return QString("diff(%1, %2, %3);").arg(function, variable, QString::number(times));
}

00094 QString MaximaCalculusExtension::integrate(const QString& function, const QString& variable)
{
    return QString("integrate(%1, %2);").arg(function, variable);
}

00099 QString MaximaCalculusExtension::integrate(const QString& function,const QString& variable, const QString& left, const QString& right)
{
    return QString("integrate(%1, %2, %3, %4);").arg(function, variable, left, right);
}

//Linear Algebra Extension
MAXIMA_EXTENSION_CONSTRUCTORS(LinearAlgebra)

//Commands to create Vectors/Matrices
00108 QString MaximaLinearAlgebraExtension::createVector(const QStringList& entries, VectorType type)
{
    QString list=entries.join(",");

    if(type==Cantor::LinearAlgebraExtension::ColumnVector)
        return QString("columnvector([%1]);").arg(list);
    else
        return QString("rowvector([%1]);").arg(list);
}

00118 QString MaximaLinearAlgebraExtension::createMatrix(const Matrix& matrix)
{
    QString cmd="matrix(";
    foreach(const QStringList& row, matrix)
    {
        cmd+='[';
        foreach(const QString& entry, row)
            cmd+=entry+',';
        cmd.chop(1);
        cmd+="],";
    }
    cmd.chop(1);
    cmd+=");";

    return cmd;
}

00135 QString MaximaLinearAlgebraExtension::identityMatrix(int size)
{
    return QString("ident(%1);").arg(size);
}

//basic functions
00141 QString MaximaLinearAlgebraExtension::rank(const QString& matrix)
{
    return QString("rank(%1);").arg(matrix);
}

00146 QString MaximaLinearAlgebraExtension::invertMatrix(const QString& matrix)
{
    return QString("invert(%1);").arg(matrix);
}

00151 QString MaximaLinearAlgebraExtension::charPoly(const QString& matrix)
{
    return QString("charpoly(%1,x);").arg(matrix);
}

00156 QString MaximaLinearAlgebraExtension::eigenVectors(const QString& matrix)
{
    return QString("eigenvectors(%1);").arg(matrix);
}

00161 QString MaximaLinearAlgebraExtension::eigenValues(const QString& matrix)
{
    return QString("eigenvalues(%1);").arg(matrix);
}

//Plotting
MAXIMA_EXTENSION_CONSTRUCTORS(Plot)

00169 QString MaximaPlotExtension::plotFunction2d(const QString& function, const QString& variable, const QString& left, const QString& right)
{
    return QString("plot2d(%1,[%2,%3,%4])").arg(function, variable, left, right);
}

00174 QString MaximaPlotExtension::plotFunction3d(const QString& function, VariableParameter var1, VariableParameter var2)
{
    const Interval& int1=var1.second;
    const Interval& int2=var2.second;
    return QString("plot3d(%1,[%2,%3,%4],[%6,%7,%8])").arg(function,
                                                           var1.first, int1.first, int1.second,
                                                           var2.first, int2.first, int2.second);
}

Generated by  Doxygen 1.6.0   Back to index