File: elim.mac

package info (click to toggle)
maxima 5.21.1-2squeeze
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 94,928 kB
  • ctags: 43,849
  • sloc: lisp: 298,974; fortran: 14,666; perl: 14,325; tcl: 10,494; sh: 4,052; makefile: 2,975; ansic: 471; awk: 24; sed: 7
file content (16 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
eliminate(eqns,vars):=block([teqns,sv,se,l,flag,dispflag],
	modedeclare([l,i],fixnum,flag,boolean),flag:dispflag:false,
	if not (listp(eqns) and listp(vars)) then error("the arguments must both be lists"),
	if length(vars)>l:length(eqns) then error("more variables then equations"),
	if l=1 then error("can't eliminate from only one equation"),
	if length(vars)=l then (vars:reverse(vars),sv:vars[1], vars:reverse(rest(vars)),flag:true),
/* ?meqhk turns [a=b] into [a-b] */
	eqns:map('?meqhk,eqns),
	for v in vars do (
		teqns:[],
		for j:1 thru l while(freeof(v,first(eqns))) do(
		  teqns:cons(first(eqns),teqns), eqns:rest(eqns)),
		if eqns=[] then eqns:teqns else (teqns:append(teqns,rest(eqns)), eqns:first(eqns), l:l-1, se:[],
		for j:1 thru l do se:cons(resultant(eqns,teqns[j],v),se),
		eqns:se)),
	if flag then [rhs(apply('ev,[last(solve(eqns[1],sv)),eval]))] else eqns)$