Hello.
Recently I bought TI-nspire CX CAS calculator and during programming I observed unexpected behavior. Namely, I wanted to calculate integral numerically from the following test(x) function say from 0 to 5.

Code:
Define LibPub test(x)=
Func
:If x<1
:Return x
:Return (x-1)^(2)+1
:EndFunc

I got an error

Code:
nInt(test(x),x,0,5)
"Error: A test did not resolve to TRUE or FALSE"


Then, I realized that this is not a problem with If statement, but much wider problem. For example, I want to integrate function w(x) where w and x are related by equation w*exp(w)=x. So, I cannot write explicit expression w=w(x), but rather have to solve this equation numerically. So, my function is

Code:
Define LibPub productlog(x)=
Func
:Return nSolve(w*exp(w)=x,w=0)
:EndFunc

Attempt to integrate it numerically causes the error:

Code:
nInt(productlog(x),x,0,1)
"Error: Argument Error"

"The first argument of nSolve must be an equation in a single variable. It cannot contain a non-valued variable other than the variable of interest."

Here we do not have If statement at all and the error is different. Looks like that nInt() tries to calculate the integral analytically first and calls the integrand with the undefined argument which triggers those errors.

By the way, I tried to integrate the same two functions numerically on Voyage 200 and it computed them without any problems.

Q.
Is this a bug in TI-nspire BASIC or intentional limitation (the feature)?

Thank you.
Several ways to do this, for instance defining the function with "when" or a system:

Thank you, Adriweb,
you are absolutely right, but you are talking about workaround. I am talking about the language specification.

Do we really have such limitation for the user defined function which is used in nInt()? If we do have, than this should be reflected in the Reference Manual or programming guide. This is VERY serious limitation which looks very artificial.

I created test() function as an illustration of the problem. My original function where I hit this problem was complicated and I decided that there is no reason to post the original code (because it was too long). I tracked down this error to the "If" statement and created a short illustration. Originally, my function what I wanted to integrate was calculated by iterations and "If" statement was used as conditional operator to stop them. You cannot remove "If" from such code. You can replace it by "While" which will cause the same error message.

I do not know the internal implementation of nInt(), but I suspect that only functions which can be called with undefined argument can be used as integrands. This means no "If" statements of any form, no "For" or "While" loops which conditions depend on the argument (explicitly or implicitly), no numerical built in functions like nSolve() or eigVI(), no inverse functions like invNorm(), invt(), invF(), invChi2(), invBinom() which arguments explicitly or implicitly depend on the formal parameter of the integrand. These are just the most obvious limitations. You can expand this list by yourself. Don't you think that this is serious limitation?

That's why I said that the problem is MUCH WIDER than the problem with the "If" statement in function test(x) which is just a "proof of concept".
Correction.
Inverse functions work fine.
  
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