Trapezoidal Rule or Simpsons Rule?
|
07-05-2015, 10:49 PM
Post: #1
|
|||
|
|||
Trapezoidal Rule or Simpsons Rule?
I'm trying to gather ideas to implement a function such as the Trapezoidal Rule, Simpsons Rule (or something similar) on the Prime.
How to supply an input function, then using values from a list, is central to this problem. Specifically, I want to be able to (programmatically) input functions, values for the lower and upper range, and the number of intervals needed, for solving them. A program might begin something like this: Code:
The input variables are the function (f), lower range (a), upper range (b), and the number of intervals (n). If you can help, thanks! -Dale- |
|||
07-06-2015, 12:33 AM
Post: #2
|
|||
|
|||
RE: Trapezoidal Rule or Simpsons Rule?
Dr. D.
Have you seen this: http://edspi31415.blogspot.com/2015/05/h...a-4th.html it seems similar to what you want. Road |
|||
07-06-2015, 11:24 AM
Post: #3
|
|||
|
|||
RE: Trapezoidal Rule or Simpsons Rule?
That is what I am trying to do, except that I want to pass-in parameters, instead of using the INPUT() statement.
The difference is that, with the INPUT() command, the type of variable CAN be specified. In Eddie's program, the variable f is type [8], which is what I need, but I want to pass the function, f, directly to the program at run time: EXPORT Trap(f,a,b,n) BEGIN END; This is the issue I'm facing at the moment. It might not be possible at this firmware revision, or, at least, I don't know how to specify input typing in the example above. Thank you for taking time to respond with that link! Input() may be the only way I can get a function into the program, for now. -Dale- |
|||
07-07-2015, 05:55 PM
(This post was last modified: 07-07-2015 08:19 PM by Arno K.)
Post: #4
|
|||
|
|||
RE: Trapezoidal Rule or Simpsons Rule?
Perhaps you want something like this:
Code:
or, after f(x):=x^3, numint(f,1,2,20), this results in 3.751875 the type-check in front allows only matching types, but the error message is not returned when it is executed the first time, that is numint(5,1,2,20) returns itself on the first run. You can easily modify it to compute via Simpsons rule in using a fifth Parameter: mode and then use some if construction. Arno |
|||
07-07-2015, 10:15 PM
(This post was last modified: 07-08-2015 10:48 AM by DrD.)
Post: #5
|
|||
|
|||
RE: Trapezoidal Rule or Simpsons Rule?
Well done! There's lots of good info in your approach, and I appreciate your contribution.
-Dale- I was puttering around also, and made a request (to Tim) to enhance calling parameters to allow specifying the TYPE of input like this: Export Trap(f[8],a[0],b[0]n[0]), etc. We'll see if that ever see's the light of day! This way the direct entry of a function (TYPE [8]) would be possible. To keep things non-CAS this approach also works: Code:
|
|||
07-08-2015, 07:39 AM
Post: #6
|
|||
|
|||
RE: Trapezoidal Rule or Simpsons Rule?
Yes, your non-CAS approach is good, too. I like to avoid side-effects,so I tend to use local vars instead of globals, so that things I used/prepared and forgot their position (was it F1 or F2?) keep intact.
Arno |
|||
07-08-2015, 10:46 AM
Post: #7
|
|||
|
|||
RE: Trapezoidal Rule or Simpsons Rule?
It's nice to have choices. I'm finding that I prefer to use the built-in globals, more so, lately. Not only do they make programs more efficient, but the more they get used, the easier it is for me to remember to clear them, before next use. Another advantage is that they are pre-TYPED, which alleviates that extra concern. In this case, I was using the contents of F1 for further activities, like the Function App, which came in handy for this; as well as for command line evaluations, for the many things I tried that didn't work so well!
-Dale- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)