// Rascal, the Advanced Scientific CALculator
// Copyright (C) 2001, Sebastian Ritterbusch (Rascal@Ritterbusch.de)
//
// 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 detauls.
//
// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
string output(const valuetaylor & a)
{
string out("taylor[");
int i;
for(i=0;i<a.dim();i++)
{
value o(output(a(i)));
if(o.isSTRING())
out+=o.asSTRING();
else
out+="Error";
if(i<a.dim()-1)
out+=" ";
}
out+="]";
return out;
}
valuetaylor matrixtotaylor(const valuematrix &a)
{
if(a.N==1)
{
if(a.M==0)
return valuetaylor();
valuetaylor res(a(0,0),a.M);
int i;
for(i=1;i<a.M;i++)
res(i)=a(0,i);
return res;
} else
{
if(a.N==0 || a.M==0)
return valuetaylor();
valuetaylor res(a(0,0),a.N);
int i;
for(i=1;i<a.N;i++)
res(i)=a(i,0);
return res;
}
}
value compute_derivative(const symrec *a)
{
#ifdef STANDALONE_VALUE
return string("Sorry, this is not supported in standalone-version!");
#else
return evaluate(a,valuetaylor(value(string("x")),value(1))).asTAYLOR()(1);
#endif
}
value dsymrec::eval(const value & a) const
{
#ifdef STANDALONE_VALUE
return string("Sorry, this is not supported in standalone-version!");
#else
int args;
if((args=arguments(iSymrec))==1)
{
value result=evaluate(iSymrec,(valuetaylor(a,1,iDiff+1))).asTAYLOR()(iDiff);
if(iDiff>1)
return result*fac(value(iDiff));
else
return result;
} else
{
if(iDiff==1)
{
valuematrix argument(args,1);
valuematrix grad(args,1);
argument(0,0)=valuetaylor(cell(a,1),1,2);
int i;
for(i=1;i<args;i++)
argument(i,0)=cell(a,i+1);
grad(0,0)=evaluate_n(iSymrec,argument).asTAYLOR()(1);
for(i=1;i<args;i++)
{
argument(i-1,0)=cell(a,i);
argument(i,0)=valuetaylor(cell(a,i+1),1,2);
grad(i,0)=evaluate_n(iSymrec,argument).asTAYLOR()(1);
}
return grad;
}
}
#endif
}
string output(const dsymrec & a)
{
#ifdef STANDALONE_VALUE
return string("Sorry, this is not supported in standalone-version!");
#else
value result=evaluate(a.iSymrec,valuetaylor(value(string("x")),value(1),a.iDiff+1)).asTAYLOR()(a.iDiff);
if(a.iDiff>1)
result=result*fac(value(a.iDiff));
if(result.isSTRING())
return result.asSTRING();
else
return output(result).asSTRING();
#endif
}
syntax highlighted by Code2HTML, v. 0.9.1