List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] more about implicitdiff:complexity and recursiveness
| [MUG] more about implicitdiff:complexity and recursiveness |
|
Author: Charles James Leonardo Quarra Cappiello
Posted: Thu, 21 Nov 2002 12:26:09 -0400
|
>> 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
|
| [MUG] Re: more about implicitdiff:complexity and recursiveness |
|
Author: Preben Alsholm
Posted: Tue, 26 Nov 2002 10:38:18 +0100
|
>> 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
>
>
>
|
| [MUG] Re: more about implicitdiff:complexity and recursiveness |
|
Author: Charles James Leonardo Quarra Cappiello
Posted: Thu, 28 Nov 2002 12:33:48 -0400
|
>> From: "Charles James Leonardo Quarra Cappiello" "charsquarra"
Thanks Preben,
I come out with a solution in the meantime (this mailing list is SLOOOW)
EfficientImplicitDiff:=proc( Limplicitderivatives::name , f::name ,
z::name , w::name , ord::integer )
local j,k,temp1,temp2;
Limplicitderivatives:=[
diff(z(w),w)=-1/f(z(w)) ]; for
k from 2 to ord do;
temp1:=diff( f(z(w))*diff(z(w),w) , w$(k-1) );
temp2:=isolate( temp1 , diff(z(w),w$k ) );
for j from 1 to k-1 do;
temp2:=op(1,temp2)=subs( Limplicitderivatives[k-j] , op(2,temp2) );
end do;
temp2:=op(1,temp2)=normal(op(2,temp2));
Limplicitderivatives:=[
op(op(Limplicitderivatives)) , temp2 ];
end do;
end proc;
The idea is that it uses L as a list where it puts the implicit derivatives
of z respect to w of increasing order, and f ,z ,w as names for f(z(w)). In
this examples, i assume that f(z(w))*diff(z(w),w) + 1 = 0; and i put that
assumption in the first entry of the list, but it could be generalized for
the case where the dependence on w is a function g(z(w))
Greetings,
Charles Quarra
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*
http://join.msn.com/?page=features/virus
|
Previous by date: [MUG] graphing parametric equations in 3d, Han Wesseling
Next by date: [MUG] Numerical error, Madham53
Previous thread: [MUG] problems with subs(), Charles James Leonardo Quarra Cappiello
Next thread: [MUG] Numerical error, Madham53
|