File: elim.mac

package info (click to toggle)
maxima 5.42.1-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 150,192 kB
  • sloc: lisp: 382,565; fortran: 14,666; perl: 14,365; tcl: 11,123; sh: 4,622; makefile: 2,688; ansic: 444; xml: 23; awk: 17; sed: 17
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)$