Thanks, Leo. This is what is happening in Maxima:
drop (L,n) := if n=1 then delete(mini(L),L,1) else drop(drop(L,n-1),1);
drop(L,n):=if n=1 then delete(mini(L),L,1) else drop(drop(L,n-1),1)
replace (L,x) := if x>mini(L) then cons(x,drop(L,1)) else L;
replace(L,x):=if x>mini(L) then cons(x,drop(L,1)) else L
finalgrade (dq,midterm,final) := ([fg],
dq: drop(dq,2),
midterm: replace(midterm,final),
fg: 3*sum(dq[i],i,1,13)/13+(midterm[1]+midterm[2])/5+3*final/10,
if fg>=89.5 then print("student got an A")
elseif fg>=84.5 then print("student got a B+")
elseif fg>=79.5 then print("student got a B")
elseif fg>=74.5 then print("student got a C+")
elseif fg>=69.5 then print("student got a C")
elseif fg>=66.5 then print("student got a D+")
elseif fg>=59.5 then print("student got a D")
else print("student got an F"), fg)$
needgrade (dq,midterm,desired) := ([need,lower,cutoff],
dq: drop(dq,2),
lower: lmin(midterm),
cutoff: 3*sum(dq[i],i,1,13)/13+(midterm[1]+midterm[2])/5+3*lower/10,
if desired>cutoff then block([],
drop(midterm,1),
need: 2*(desired-3*sum(dq[i],i,1,13)/13-midterm[1]/5))
else need:
10/3*(desired-3*sum(dq[i],i,1,13)/13-(midterm[1]+midterm[2])/5),need)$
needgrade([10,10,0,10,10,10,10,10,0,10,0,10,10,10,10],[62,85],8.45b1);
8.881538461538462b1
finalgrade([10,10,0,10,10,10,10,10,0,10,0,10,10,10,10],[62,85],8.88b1);
"student got a B+"
8.909230769230769b1
If these programs worked properly, the output of the last command would be
near 8.45b1. (Note that these are test values, not any student's actual
grades, so this should be legally and morally okay.)
On Fri, Jun 25, 2010 at 09:21, Leo Butler <l.butler at ed.ac.uk> wrote:
>
>
> On Thu, 24 Jun 2010, Jeffrey Hankins wrote:
>
> < Okay...I cannot for the life of me figure out what is wrong with my code.
> The functions finalgrade and needgrade are supposed to reverse one another,
> but this is
> < not what happens when I actually execute them. If anyone can read Maxima
> program code, I would be interested if they could tell me where I went wrong
> (unless it's
> < a Maxima issue). finalgrade seems to be all right; the problem could be
> the if part of needgrade. This is pretty discouraging, especially
> considering that I
> < haven't programmed in Maxima for very long.
> <
> < load(descriptive);
> <
> < drop (L,n) := if n=1 then delete(mini(L),L,1) else drop(drop(L,n-1),1);
> <
> < replace (L,x) := if x>mini(L) then cons(x,drop(L,1)) else L;
> <
> < finalgrade (dq,midterm,final) := ([fg],
> < dq: drop(dq,2),
> < midterm: replace(midterm,final),
> < fg: 3*sum(dq[i],i,1,13)/13+(midterm[1]+midterm[2])/5+3*final/10,
> < if fg>=89.5 then print("student got an A")
> < elseif fg>=84.5 then print("student got a B+")
> < elseif fg>=79.5 then print("student got a B")
> < elseif fg>=74.5 then print("student got a C+")
> < elseif fg>=69.5 then print("student got a C")
> < elseif fg>=66.5 then print("student got a D+")
> < elseif fg>=59.5 then print("student got a D")
> < else print("student got an F"), fg)$
> <
> < needgrade (dq,midterm,desired) := ([need,lower,cutoff],
> < dq: drop(dq,2),
> < lower: lmin(midterm),
> < cutoff: 3*sum(dq[i],i,1,13)/13+(midterm[1]+midterm[2])/5+3*lower/10,
> < if desired>cutoff then block(
> < drop(midterm,1),
> < need: 2*(desired-3*sum(dq[i],i,1,13)/13-midterm[1]/5))
> < else need:
> 10/3*(desired-3*sum(dq[i],i,1,13)/13-(midterm[1]+midterm[2])/5),need)$
> <
> <
>
> Jeffrey,
> To create an environment with local variables, use
>
> block([x], ...)
>
> The construction
> ([x], ...)
>
> evaluates the list [x], and then the subsequent expressions.
>
> Could you send an example that shows what your code produces
> and what you would like it to produce?
>
> Leo
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>