File: ode1_factor.mac

package info (click to toggle)
maxima-sage 5.45.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 113,788 kB
  • sloc: lisp: 440,833; fortran: 14,665; perl: 14,369; tcl: 10,997; sh: 4,475; makefile: 2,520; ansic: 447; python: 262; xml: 59; awk: 37; sed: 17
file content (88 lines) | stat: -rw-r--r-- 2,578 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Solution of first order ODEs by factoring
   
  References: 
 
  Daniel Zwillinger, Handbook of Differential Equations, 3rd ed
  Academic Press, (1997), pp 265-266


  Copyright (C) 2004 David Billinghurst		 
  		       								 
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ 

put('ode1_factor,001,'version)$

ode1_factor(eq,y,x):= block( 
  [de,%p,ans:[],s,inflag:true,powflag:true,u,factors:[]],

  ode_disp("    in ode1_factor"),  

  /* substitute %p=y' */
  de: expand(lhs(eq)-rhs(eq)),
  de: subst(%p,'diff(y,x),de),
  
  /* At present restricted to simple cases such as p^2+5p+6=0
     What about repeated factors? */
  
  /* if ( not(freeof(x,y,de)) ) then return(false), */

  de:factor(de),
  /* fail if the ode wasn't simplified by factoring */
  if ( not(inpart(de,0)="*") or is(length(de)<2) ) then (
    ode_disp2("     cannot factor",de),
    return(false)
  ),

  /* Count the factors that are DEs. There may be constant terms 
     Some test cases failed when this was combined with the loop below */
  for u in de do (
    if not(freeof(%p,u)) then (
      factors:endcons(u,factors)
    )
  ),
  
  if length(factors)<2 then (
    ode_disp2("     cannot factor",de),
    return(false)
  ),
  ode_disp2("    and after factoring is ",de),

  for u in de do (
    /* Do not continue for higher order terms (including repeated factors) */
    if hipow(expand(u),%p)>1 then (
      ode_disp2("      unsuitable term ",u),
      powflag:false
    )
  ),
  if powflag=false then return(false),

  /* For each factor, try and solve ODE */
  for u in factors do (
    ode_disp2("      Factor ",u),
    if not(freeof(%p,u)) then (
      s:ode2(subst('diff(y,x),%p,u)=0,y,x),
      ode_disp2("      has solution",s),
      if s#false then ans:endcons(s,ans)
    )
  ),

  if ans#[] then (
    method:'factor,
    ans
  )
  else
    false
)$