Subject: Newbie seeks help with evalution of forms
From: Robert Grieve
Date: Mon, 19 May 2008 23:13:56 +1200
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20080519/d71bbd76/attachment.pgp