Hi,

I've been using my TI-Nspire to find Riemann sums. I created a program that goes like this:


Code:

Prgrm
Request "Function",f(x)
Request "Start of Interval:",a
Request "End of Interval:",b
Request "Number of rectangles:",n
0→l
0→m
(b-a)/d→n
For i,0,n-1
l+f(a+d*i)*d→l
m+f(a+d*i)*d→m
EndFor
l-f(a)*d+f(a+d*n)*d→r
(l+r)/2→t
Disp "Left Sum:"
Disp approx(l)
Disp "Right Sum:"
Disp approx(r)
Disp "Midpoint Sum:"
Disp approx(m)
Disp "Trapezoidal Sum:"
Disp approx(t)
EndPrgm


This program runs perfectly on my N-Spire. However when I tried to program this onto my friend's TI-89 Titanium, I get an error because it won't accept g(x) as an argument for the first Request (Input) statement. I have tried to input it as a string and convert it to an expression with the expr() command, but when I run this code:

Code:

InputStr "Function:",f(x)
expr(f)→f(x)

it throws an argument error. I have tried using the #indirection command but when I do this I still get an error or an incorrect answer. I have seen Riemann sum programs that don't store a function, but I was wondering if it is possible to do it like I have done on the N-Spire by storing a function and then using that function to find the sum.

I would greatly appreciate any help,
Thanks in advance
Sorry, I don't have much time at the moment to look for a better solution, but try this:


Code:

InputStr "function", n
expr(n & "->f(x)")


Did not test it, but might be worth a shot.
Thank you so much Jim Bauwens now it runs perfectly thanks for the help.
I guess i misunderstood the use of the expr() function, I thought it merely converts a string to an expression, but I guess it actually executes a command if you concatenate it with a command at the end. Thanks for helping me clarify that.
Yep, it can be used to do both. It can be a very powerful function. I've used it to great effect to do things like execute dynamically-generated TI-BASIC code. Smile
Travis wrote:
execute dynamically-generated TI-BASIC code


Surprised I clearly underestimated expr( in my current programs. I'll have to make note of these things.
Glad it worked Smile
Yes, expr is very powerful indeed!
All right here is the program on ticalc.org thanks again.

http://www.ticalc.org/archives/files/fileinfo/451/45120.html
http://www.ticalc.org/cgi-bin/zipview?89/basic/math/calculus/riemannsums.zip;ReadMe.txt

Cemetech:
http://www.cemetech.net/programs/index.php?mode=file&id=822
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement