deTaylor
05-22-2015, 01:24 PM (This post was last modified: 05-22-2015 01:39 PM by fhub.)
Post: #1
 fhub Member Posts: 191 Joined: Dec 2013
deTaylor
Here's a small CAS function deTaylor for the HP-Prime (similiar to deSolve) which I've originally written for Xcas.
It approximately solves 1st- and 2nd-order differential equations (with initial conditions) as n-th degree Taylor polynomial.

1st order y'=f(x,y) with y(x0)=y0:
deTaylor(f,[x,y],[x0,y0],n)

2nd order y''=f(x,y,y') with y(x0)=y0 and y'(x0)=y0':
deTaylor(f,[x,y,z],[x0,y0,z0],n)
(I'm using z instead of y', because y' can't be used as input)

Here's the function definition:
(you can directly copy&paste it into the Prime-emulator commandline in CAS-mode)
Code:
 deTaylor(f,v,c,n):= BEGIN   local k,yk,sol;   yk:=v(2); sol:=c(2);   IF dim(v)<2 or dim(v)>3 or dim(v)<>dim(c) THEN     RETURN("Argument error!");   END;   FOR k FROM 1 TO n STEP 1 DO     IF dim(v)=2 THEN       yk:=diff(yk,v(1))+f*diff(yk,v(2));       sol+=subst(yk,[v(1)=c(1),v(2)=c(2)])/k!*(v(1)-c(1))^k;     ELSE       yk:=diff(yk,v(1))+v(3)*diff(yk,v(2))+f*diff(yk,v(3));       sol+=subst(yk,[v(1)=c(1),v(2)=c(2),v(3)=c(3)])/k!*(v(1)-c(1))^k;     END;   END;   expand(simplify(sol)); END

Example 1: y'=x*y^2+1 with y(0)=1 (6th-degree approximation):
deTaylor(x*y^2+1,[x,y],[0,1],6)

Example 2: y''=x*y*y' with y(1)=2 and y'(1)=3 (5th degree):
deTaylor(x*y*z,[x,y,z],[1,2,3],5)

Maybe it's useful for someone,
Franz
 « Next Oldest | Next Newest »

 Messages In This Thread deTaylor - fhub - 05-22-2015 01:24 PM RE: deTaylor - salvomic - 05-22-2015, 06:10 PM RE: deTaylor - fhub - 05-22-2015, 08:27 PM RE: deTaylor - salvomic - 05-22-2015, 08:31 PM RE: deTaylor - fhub - 05-22-2015, 09:44 PM RE: deTaylor - salvomic - 05-22-2015, 10:13 PM

User(s) browsing this thread: 1 Guest(s)