File: elim.mc

package info (click to toggle)
maxima 5.6-17
  • links: PTS
  • area: main
  • in suites: woody
  • size: 30,572 kB
  • ctags: 47,715
  • sloc: ansic: 154,079; lisp: 147,553; asm: 45,843; tcl: 16,744; sh: 11,057; makefile: 7,198; perl: 1,842; sed: 334; fortran: 24; awk: 5
file content (16 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (3)
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)$