been writing a program to do definite integral approx. but i cant get the Simpson approxiamtion to work right..... both of the others seem to work perfectly... i suspect a variable is getting changed... but i dont see anything that is changing it... and
MY logic must be perfect.... anyone see the problem? (i hate programming on these things... such a cramped screen and debuggin is a real pita)
explanation of variables: x-start interval to be integrated; L=end of interval;N=number of iterations;O=offset % for rieman sum.... ooh and several variables get used for different things through the prog...
(comments are denoted by #s)
Code:
0->A
Prompt x,L,N,O #get those numbers! note: we're analysing the eqn y1
x->xx #store a dummy; we'll use it later
(L-x)/iPart(N)->N #make sure that #%^& user entered a whole number!
x+N*O/100->x #offset the start sample pt for rieman sum
for(x,x,L-(n*0/100),N) # stmt L-(n*o/100) is untested (was using an if before)
y1+A->A
end
Disp "riemann:",N*A
(evalf(y1,x,xx)+evalf(y1,x,L))/2->A #dividing 1st and last sample pt of trap integ by 2
for(x,xx+N,L-N,N)
y1+A->A
end
Disp "Trap:",N*A
(L-xx)/N->N #get back our orginal number N and make it even
if fPart (n/2)==.5:n+1->N
(L-xx)/N->N
evalf(y1,x,xx)+evalf(y1,x,L)->A #puting the first and last sample in
For(x,xx+N,L-2N,2N) #all the odd samples
4*evalf(y1,x,x)+A->A
end
For(x,xx+2N,L-N,2N) #even ones
2*evalf(y1,x,x)+A->A
end
Disp "Simpson:",N*A/3 #output