Subject: Newbie seeks help with evalution of forms
From: Stavros Macrakis
Date: Mon, 19 May 2008 07:43:20 -0400
Yes, the documentation for ev is a mess, but the good news is that you
don't need ev at all.
Your yform is not a function, and Maxima can't apply it as a function
as its error message correctly reports. After all, what if yform were
x-y -- would yform(2) be 2-y or x-2?
To substitute a particular value for a variable in an expression, you
can use subst( xxx , 'x, expr ), with its simple semantics. You could
also use ev( expr, x=xxx ), but ev is a Swiss army knife, and it'
generally better to use a single-purpose tool.
-s
On 5/19/08, Robert Grieve <sonofthejedi at xtra.co.nz> wrote:
> Hello all.
> I am trying to write a function to calculate the error in the
> approximation to the area under a curve. I am using the rectangle
> approximation method. It turns out that the error is
> of the form a/n. a has a value which I have a function to calculate.
> It needs a formula for the curve as an argument.
> This is the yform
>
> /*
> * The first thing to do is get the error in a one
> * rectangle approximation of the area under yform.
> * yform: The formula for the curve
> * lo: lower limit of area for approximation
> * hi: upper limit of area for approximation
> *
> * returns the same type as rat.
> */
> toterr(yform,lo,hi) := block(
> [n:1],
> steps : makelist((lo + i*((hi-lo)/n)),i,0,n-1),
> errors : create_list(((hi - lo)/n)*
> (yform(j+((hi-lo)/n)) - yform(j)),
> j,steps),
> rat(apply("+",errors))
> );
>
> /* What I want to do below is, having got the number from the func
> * above, i want to use the result in an inequality.
> * -- Dons asbestos long-johns --
> * The trouble is, i think some part of the evaluation is broken,
> * and ev's docs are THE MOST CONFUSING THING I HAVE SEEN IN _N YEARS_
> * --End of flame-fest--
> */
>
> find_n(yform,lo,hi, d,q) := block(
> [eq: yform],
> err : toterr(yform,lo,hi),
> err/n < d/q
> );
> (%o7) toterr(yform,lo,hi):=
> (%o8) find_n(yform,lo,hi,d,q):=
> block([eq:yform],err:toterr(yform,lo,hi),err/n<d/q)
>
> (%i10) find_n(x^2,-2,2,1,100);
> yform evaluates to x^2
> Improper name or value in functional position.
> #0: toterr(yform=x^2,lo=-2,hi=2)
> #1: find_n(yform=x^2,lo=-2,hi=2,d=1,q=100)
> -- an error. To debug this try debugmode(true);
> (%i11)
>
> Please can someone correct my ignorance, and please forgive me.
>
> Best Rob Grieve
>
--
Sent from Gmail for mobile | mobile.google.com