>> From: Preben Alsholm "P.K.Alsholm"
Here are two solutions. As they are written the output is a Taylor
polynomial. The last one is by far the fastest. It makes use of
implicitdiff just once and then dsolve/series. The only problem with
that one is that dsolve/series has a bug that makes it unreliable.
The case below is not affected by that bug.
restart;
> implicittaylor1:=proc(eq::equation,L::list(name=algebraic),n::posint)
> local x,y,x0,y0,EQ,ym,k;
> x,y:=op(map(lhs,L));
> x0,y0:=op(map(rhs,L));
> EQ:=subs(y=y(x),eq);
> for k to n do
> EQ:=diff(EQ,x);
>
ym[k]:=eval(solve(EQ,diff(y(x),x$k)),{x=x0,y(x)=y0,seq(diff(y(x),x$i)=ym[i],i=1..k-1)})
> end do;
> y0+add(ym[k]*(x-x0)^k/k!,k=1..n)
> end proc:
> eq1:=x^2*y+x^3+y^4-3*y+2 = 0:
> time(implicittaylor1(eq1,[x=0,y=1],25));
30.754
> implicittaylor2:=proc(eq::equation,L::list(name=algebraic),n::posint)
local x,y,x0,y0,ODE,ym,k;
> x,y:=op(map(lhs,L));
> x0,y0:=op(map(rhs,L));
> ODE:=diff(y(x),x)=subs(y=y(x),implicitdiff(eq,y,x));
> Order:=n+1;
> convert(rhs(dsolve({ODE,y(x0)=y0},y(x),type=series)),polynom)
> end proc:
> time(implicittaylor2(eq1,[x=0,y=1],25));
1.102
The bug in dsolve/series is exhibited here:
> restart;
> Order:=2:
This is fine:
> dsolve({diff(y(x),x)=f(x,y(x)),y(x0)=y0},y(x),type=series);
2
y(x) = y0 + f(x0, y0) (x - x0) + O((x - x0) )
this is not
> dsolve({diff(y(x),x)=f(x+y(x)),y(x0)=y0},y(x),type=series);
2
y(x) = y0 + f(y0) (x - x0) + O((x - x0) )
nor is this
> dsolve({diff(y(x),x)=x*f(x+y(x)),y(x0)=y0},y(x),type=series);
2
y(x) = y0 + x0 f(y0) (x - x0) + O((x - x0) )
Preben Alsholm
Department of Mathematics
Technical University of Denmark
Charles James Leonardo Quarra Cappiello wrote:
>>>From: "Charles James Leonardo Quarra Cappiello" "charsquarra"
>>
>
> Hi,
>
> I've noted that the time of calculation of implicitdiff( eq(z,w) , z , w$n
> ); grows very quick with n, since in most calculations of the n-th implicit
> derivative of z respect of w, one has usually:
>
> n n-1 n-2
> d z d z d z dz
> --- = f ( ----- , ----- , -- , z , w );
> n n-1 n-2
> dw dw dw dw
>
> now, in a particular calculation im in need of calculating all k-th implicit
> derivatives from 1 to n, but it looks like each timestep, each k=1..n-1
> derivatives are recalculated, amounting to an enourmous waste. Any ideas how
> could implicitdiff reuse the results of the n-1 previous implicit
> derivatives to calculate the n-th one?
>
> Greetings,
>
> Charles Quarra
>
>
>
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
>
>
|