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
 slawek39 Member Posts: 74 Joined: Jun 2014
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.

05-01-2016, 04:38 PM (This post was last modified: 05-01-2016 04:46 PM by Tim Wessman.)
Post: #2
 Tim Wessman Senior Member Posts: 2,209 Joined: Dec 2013
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.
05-01-2016, 04:53 PM
Post: #3
 slawek39 Member Posts: 74 Joined: Jun 2014
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)
05-01-2016, 05:39 PM (This post was last modified: 05-01-2016 05:40 PM by slawek39.)
Post: #4
 slawek39 Member Posts: 74 Joined: Jun 2014
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.
05-02-2016, 02:15 AM
Post: #5
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
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 . . .
05-02-2016, 05:47 AM
Post: #6
 parisse Senior Member Posts: 1,051 Joined: Dec 2013
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.
05-02-2016, 02:20 PM
Post: #7
 parisse Senior Member Posts: 1,051 Joined: Dec 2013
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.
05-02-2016, 02:39 PM
Post: #8
 parisse Senior Member Posts: 1,051 Joined: Dec 2013
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.
05-02-2016, 03:18 PM
Post: #9
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
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).
05-02-2016, 04:49 PM
Post: #10
 slawek39 Member Posts: 74 Joined: Jun 2014
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
05-03-2016, 05:14 AM (This post was last modified: 05-03-2016 05:16 AM by parisse.)
Post: #11
 parisse Senior Member Posts: 1,051 Joined: Dec 2013
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...)
05-03-2016, 08:16 AM
Post: #12
 parisse Senior Member Posts: 1,051 Joined: Dec 2013
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.
05-03-2016, 02:28 PM
Post: #13
 Helge Gabert Senior Member Posts: 460 Joined: Dec 2013
RE: error in the integration of complex functions (FW10077)
Great news, and thanks for the explanation!
 « Next Oldest | Next Newest »

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