Post Reply 
error in the integration of complex functions (FW10077)
05-01-2016, 02:46 PM (This post was last modified: 05-01-2016 02:48 PM by slawek39.)
Post: #1
error in the integration of complex functions (FW10077)
The integration of the function ft(x,CEILING(x)) gives erroneous results. My TI V200 gives different results.

   
   
   
   
Find all posts by this user
Quote this message in a reply
05-01-2016, 04:38 PM (This post was last modified: 05-01-2016 04:46 PM by Tim Wessman.)
Post: #2
RE: error in the integration of complex functions (FW10077)
I don't have an 89/200 emulator or unit handy, but the nspire emu seems to perfectly match the prime output with my function I just made. Can you post your code/function definition, and maybe a picture of the expected output?

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
05-01-2016, 04:53 PM
Post: #3
RE: error in the integration of complex functions (FW10077)
(05-01-2016 04:38 PM)Tim Wessman Wrote:  Can you post what you are expecting the results to be?


The graph is the same on both calculators. However, the integration gives the other (non-zero) results on TI V200.

The first integral from last screenshot (0 to 2) on TI V200: 0.076247465759
The second integral from last screenshot (0 to 1) on TI V200: 0.841470984808

On HP Prime (FW10077) both integrals: 0 (obvious error if you look at the graph)
Find all posts by this user
Quote this message in a reply
05-01-2016, 05:39 PM (This post was last modified: 05-01-2016 05:40 PM by slawek39.)
Post: #4
RE: error in the integration of complex functions (FW10077)
Code/function definition from TI V200:

:f(x,n)
:Func
:Local i,s
:0->s
:For i,1,n
: s+cos(i*x)->s
:EndFor
:EndFunc

Grapg is the same but integral from f(x,ceiling(x)) id different.
Find all posts by this user
Quote this message in a reply
05-02-2016, 02:15 AM
Post: #5
RE: error in the integration of complex functions (FW10077)
It seems like the built-in integration routines (int, but also romberg) have trouble with discontinuities. Same result (0) is obtained for int(ft(x,1/x),0,1) or int(ft(x, 10*sin(x)),0,1). Or any other bounds between 0 and 1, for that matter.

It is also interesting that a plot of ceiling(X) and ft(X, ceiling(X)): plot menu: signed area recognizes ft, but if the user attempts to calculate the area between both functions, the result is only for the area between ceiling(X) and the X-axis.

Of course, one can always write his/her own integration routine . . . Smile
Find all posts by this user
Quote this message in a reply
05-02-2016, 05:47 AM
Post: #6
RE: error in the integration of complex functions (FW10077)
Please enter your function in plain text (like it was done for the TI), not as a screenshot, so that it's easy to copy/paste it to check. I don't have time to enter all reported questions here by hand.
Find all posts by this user
Quote this message in a reply
05-02-2016, 02:20 PM
Post: #7
RE: error in the integration of complex functions (FW10077)
If f is entered as an algebraic function, you get the exact answer
Code:
f(x,n):=sum(cos(k*x),k,1,n);
int(f(x,ceil(x)),x,0,2);
returns 4*tan(1)/(tan(1)^4+2*tan(1)^2+1)+2*tan(1/2)/(tan(1/2)^2+1)-4*tan(1/2)/(tan(1/2)^4+2*tan(1/2)^2+1)
If f is entered as a program
Code:
f(x,n):= begin local j,y; y:=0; for j from 1 to n do y:=y+cos(j*x); end; end;
then f(x,ceiling(x)) returns an error in Xcas while returning 0.0 on the Prime. I guess it's again because an exception is not raised on the Prime. This explains why you get 0 for the integral.
Find all posts by this user
Quote this message in a reply
05-02-2016, 02:39 PM
Post: #8
RE: error in the integration of complex functions (FW10077)
The best workaround I've found for a function like that (where evaluation with x symbolic should fail) is
Code:
romberg('f(x,ceiling(x))',x,0.0,2.0);
gaussquad would give a better approximation than romberg, but it is unfortunately not activated on the Prime.
Find all posts by this user
Quote this message in a reply
05-02-2016, 03:18 PM
Post: #9
RE: error in the integration of complex functions (FW10077)
Interesting . . . So why is it that quoting f, i.e., 'f(x,ceiling(x))', works with romberg?

I always thought that int() is based on the gaussian quadrature. Any chance gaussquad could be made available for the Prime? (that is probably a question for Tim).
Find all posts by this user
Quote this message in a reply
05-02-2016, 04:49 PM
Post: #10
RE: error in the integration of complex functions (FW10077)
(05-02-2016 05:47 AM)parisse Wrote:  Please enter your function in plain text (like it was done for the TI), not as a screenshot, so that it's easy to copy/paste it to check. I don't have time to enter all reported questions here by hand.

The function in text format:

#cas
ft(x,n):=
BEGIN
LOCAL i,s:=0;
FOR i FROM 1 TO n DO
s+COS(i*x)▶s
END
END;
#end
Find all posts by this user
Quote this message in a reply
05-03-2016, 05:14 AM (This post was last modified: 05-03-2016 05:16 AM by parisse.)
Post: #11
RE: error in the integration of complex functions (FW10077)
(05-02-2016 03:18 PM)Helge Gabert Wrote:  Interesting . . . So why is it that quoting f, i.e., 'f(x,ceiling(x))', works with romberg?
Because the problem is in evaluating f(x,ceiling(x)), not in numerical integration. Quoting prevents evaluation. The program evaluation raises an exception because the test in the loop can not be evaluated with x symbolic, but the Prime does not have exceptions. This means that if I want to fix this bug, I must mimic the exception mechanism by handcoding specific error code (and this is an endless game...)
Find all posts by this user
Quote this message in a reply
05-03-2016, 08:16 AM
Post: #12
RE: error in the integration of complex functions (FW10077)
As I feared it requires a lot of small changes ... but now I can get the exact answer which was a surprise to me.
Find all posts by this user
Quote this message in a reply
05-03-2016, 02:28 PM
Post: #13
RE: error in the integration of complex functions (FW10077)
Great news, and thanks for the explanation!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)