Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Need to Compute Trigonometric Function

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Need to Compute Trigonometric Function
 Login/Join
 
Platinum Member
posted
I need to perform some calculations in my WebFOCUS report that involves using some trigonometric functions...cosine, tangent, and sine. Has anyone used cosine, tangent, or sine functions in their calculations?

This message has been edited. Last edited by: FP Mod Chuck,


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Virtuoso
posted Hide Post
What's the goal of your trigonometry? Are you operating on map coordinates perhaps? In that case it probably pays off to look at a GIS package for your calculations. I don't know how well WF supports those though.

If not, perhaps your easiest solution is to do your calculations in SQL, directly on the RDBMS where your data lives.

An alternative solution is to create a library that defines WebFOCUS function hooks. See: http://infocenter.informationb.../source/topic239.htm

Be aware though that calls to custom WF functions can (probably) not be translated to SQL, so use those either in COMPUTEs (as opposed to DEFINEs) or on local tables (FOCUS, binary, CSV, etc).


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Platinum Member
posted Hide Post
Thanks for the response Wep5622. The goal is strictly computing a ratio using cosine, tangent, or sine. For example, here is one of the calculations (Avg Power Factor) that I need to compute:

PF avg = cos(tan-1(kVArh/kWh))


I need to know how to reference the cosine and tangent within the function/subroutine.


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Expert
posted Hide Post
Let me Google that for You


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Platinum Member
posted Hide Post
Tom, I have googled also, but I don't see how to reference cosine or tangent for a calculation in a WebFOCUS function or whatever. Do you?


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Platinum Member
posted Hide Post
I am just boarding my flight home from Summit. I think I have the trig functions in my edasprof.

I will check it out tonight.


WebFOCUS 8.2.03 - Production
WebFOCUS 8.2.04 - Sand Box
Windows 2012 R2 Server
HTML, PDF, Excel
In FOCUS since 1980
 
Posts: 115 | Location: Seattle, WA | Registered: April 07, 2015Report This Post
Platinum Member
posted Hide Post
Michael - Thanks for checking. I appreciate anything you have to post on it. Thanks.


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Virtuoso
posted Hide Post
quote:
tan-1(...)


That (with -1 as a superscript) appears to denote arc tangent

This message has been edited. Last edited by: j.gross,
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Platinum Member
posted Hide Post
I have spent most of my 37 years in (Web)FOCUS using it as a language to track scientific projects. We worked a lot in spatial relations, so I have written a bunch of reports that use trig functions. The last couple of years I have been on the finance side Mad and had to dig this out of my archives.

Here you go.

-**************** Define Trig Functions ***********************
DEFINE FUNCTION F_SIN(angle/D8.5)
PI/D31.29 = 3.14159265358979;
XVAL/D31.29=angle/180*PI;
XSQ/D31.29 = XVAL *XVAL ; 
RESID/D31.29 = XSQ * 0.5 ; 
COSIA/D31.29 = 1 - RESID ; 
RESIDA/D31.29 = XSQ * .0833333333333333 * RESID ; 
RESIDB/D31.29 = XSQ * .0333333333333333 * RESIDA ; 
RESIDC/D31.29 = XSQ * .0178571428571429 * RESIDB ; 
RESIDD/D31.29 = XSQ * .0111111111111111 * RESIDC ; 
RESIDE/D31.29 = XSQ * .00757575757575758 * RESIDD ; 
RESIDF/D31.29 = XSQ * .00549450549450550 * RESIDE ; 
RESIDG/D31.29 = XSQ * .00416666666666667 * RESIDF ; 
RESIDH/D31.29 = XSQ * .00326797385620915 * RESIDG ; 
RESIDI/D31.29 = XSQ * .00263157894736842 * RESIDH ; 
RESIDT/D31.29 = -RESIDI + 
RESIDH-RESIDG+RESIDF-RESIDE+RESIDD-RESIDC+RESIDB- RESIDA; 
COSIN/D31.25 = COSIA - RESIDT ; 
COSINS/D31.25 = COSIN * COSIN ; 
F_SIN/D31.25 = SQRT(1.0 - COSINS) ; 
END
DEFINE FUNCTION F_COS(angle/D8.5)
PI/D31.29 = 3.14159265358979;
XVAL/D31.29=angle/180*PI;
XSQ/D31.29 = XVAL *XVAL ; 
RESID/D31.29 = XSQ * 0.5 ; 
COSIA/D31.29 = 1 - RESID ; 
RESIDA/D31.29 = XSQ * .0833333333333333 * RESID ; 
RESIDB/D31.29 = XSQ * .0333333333333333 * RESIDA ; 
RESIDC/D31.29 = XSQ * .0178571428571429 * RESIDB ; 
RESIDD/D31.29 = XSQ * .0111111111111111 * RESIDC ; 
RESIDE/D31.29 = XSQ * .00757575757575758 * RESIDD ; 
RESIDF/D31.29 = XSQ * .00549450549450550 * RESIDE ; 
RESIDG/D31.29 = XSQ * .00416666666666667 * RESIDF ; 
RESIDH/D31.29 = XSQ * .00326797385620915 * RESIDG ; 
RESIDI/D31.29 = XSQ * .00263157894736842 * RESIDH ; 
RESIDT/D31.29 = -RESIDI + 
RESIDH-RESIDG+RESIDF-RESIDE+RESIDD-RESIDC+RESIDB- RESIDA; 
F_COS/D31.25 = COSIA - RESIDT ; 
END
DEFINE FUNCTION F_TAN(angle/D8.5)
PI/D31.29 = 3.14159265358979;
XVAL/D31.29=angle/180*PI;
XSQ/D31.29 = XVAL *XVAL ; 
RESID/D31.29 = XSQ * 0.5 ; 
COSIA/D31.29 = 1 - RESID ; 
RESIDA/D31.29 = XSQ * .0833333333333333 * RESID ; 
RESIDB/D31.29 = XSQ * .0333333333333333 * RESIDA ; 
RESIDC/D31.29 = XSQ * .0178571428571429 * RESIDB ; 
RESIDD/D31.29 = XSQ * .0111111111111111 * RESIDC ; 
RESIDE/D31.29 = XSQ * .00757575757575758 * RESIDD ; 
RESIDF/D31.29 = XSQ * .00549450549450550 * RESIDE ; 
RESIDG/D31.29 = XSQ * .00416666666666667 * RESIDF ; 
RESIDH/D31.29 = XSQ * .00326797385620915 * RESIDG ; 
RESIDI/D31.29 = XSQ * .00263157894736842 * RESIDH ; 
RESIDT/D31.29 = -RESIDI + 
RESIDH-RESIDG+RESIDF-RESIDE+RESIDD-RESIDC+RESIDB- RESIDA; 
COSIN/D31.25 = COSIA - RESIDT ; 
COSINS/D31.25 = COSIN * COSIN ; 
SIN/D31.25 = SQRT(1.0 - COSINS) ; 
F_TAN/D31.25 = SIN/COSIN;
END
-******************* End Trig Functions ***********************
  


I'm pretty sure a long ago Focal Pointer gave me these.


WebFOCUS 8.2.03 - Production
WebFOCUS 8.2.04 - Sand Box
Windows 2012 R2 Server
HTML, PDF, Excel
In FOCUS since 1980
 
Posts: 115 | Location: Seattle, WA | Registered: April 07, 2015Report This Post
Virtuoso
posted Hide Post
It is possible to create a C (or FORTRAN, etc) library containing those functions wrapped for use in FOCUS. The C programming language (and the others probably do to) has implementations for sin, cos, tan, atan, etc. that you can use in your functions.

Since you're working with pure numbers, you probably won't have to worry about memory allocation, so the problem boils down to writing some simple wrappers and getting them to compile as a library.

The resulting library should go in your WF server directory under wfs/user/.
After that, you can call your functions just like that.

There are a few benefits to going this route over a DEFINE FUNCTION implementation, namely that it will probably perform better and that you're using an implementation that's well-established.

For a start of a C library, your exported functions would look something like this:
#ifndef TRIGONOMETRY_H
#define TRIGONOMETRY_H

#  ifdef MINGW32
#    define EXPORT     __attribute__((visibility("default")))
#    define HIDDEN     __attribute__((visibility("hidden")))
#  else
#    define EXPORT     __declspec(dllexport)
#    define HIDDEN     
#  endif

void EXPORT sin(double*, double*);
void EXPORT cos(double*, double*);
void EXPORT tan(double*, double*);

void EXPORT asin(double*, double*);
void EXPORT acos(double*, double*);
void EXPORT atan(double*, double*);

#endif


Where the first parameter of each function is the input value and the second is the result value.

You would use them like this:
TABLE FILE foo
PRINT
    COMPUTE avg/D12.6 = COS(ATAN(kVArh / kWh, 'D12.6'), avg);
BY etc
END


If you're not comfortable writing C code, there are people who do that for $$$. IBI comes to mind, but perhaps a nearby computer science student or so can do that cheap (and hopefully reliable).


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Platinum Member
posted Hide Post
Thanks Michael and Wep5622. I will take a look at these and will let you know if I have any additional questions.


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Platinum Member
posted Hide Post
Michael L Meagher - I ran this simple test below calling your F_TAN trig functions and I got data returned successfully. I used 3 as a input value. The output is below also.

TABLE FILE MDM_READINGS
PRINT AMI_METER_ID
COMPUTE FUNC_TEST/D12.8 = F_TAN(3);
WHERE READLIMIT EQ 10;
END
-RUN

AMI_METER_ID FUNC_TEST
119573625 .05240778
118734379 .05240778
118472154 .05240778
118588201 .05240778
118471538 .05240778
133815474 .05240778
118734401 .05240778
118471050 .05240778
118740351 .05240778
118472737 .05240778

I need to compute the arc tangent (tan to the -1 power)of that corresponding calculation....and then the cosine of that, such as below. Do you have one that will calculate the arc tangent?

cos(tan-1(kVArh/kWh))


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Expert
posted Hide Post
Hi AMC,

If you searched the forum using "sine cosine" you would have found that this has been asked before. You will also find that someone asked about distance calculation as well.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Platinum Member
posted Hide Post
Tony - When I searched, I believe I searched the whole knowledge base and may have overlooked that post by you before. So, I see you posted functions to calculate the sine and cosine of an angle about a year ago and I see that Glenda found and posted a distance equation using ATAN2(y,x) in 2007. To clarify, I can use this ATAN2 equation where y is the numerator in my equation and the x is the denominator in my equation I posted above?


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Expert
posted Hide Post
AMC,

Whilst I did a very basic sine and cosine function back then, I ultimately used Edward Wolfgram's version as it was more accurate.

I never ventured to the arctan function though.

I did look at the function POWER but I am not sure whether it will accept the negative power (-1) that you require.

I am sure that there are a few minds out there now, just trying to prove that this can be achieved Smiler

Good luck

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Virtuoso
posted Hide Post
According to http://mathworld.wolfram.com/InverseTangent.html calculating the arctan involves imaginary number arithmatic:
quote:
The inverse tangent is a multivalued function and hence requires a branch cut in the complex plane, which the Wolfram Language's convention places at (-iinfty,-i] and [i,iinfty). This follows from the definition of tan^(-1)z as
tan^(-1)z=1/2i[ln(1-iz)-ln(1+iz)].


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Virtuoso
posted Hide Post
On a different note; where are your numbers coming from?

If that's an RDBMS, chances are that the RDBMS implemented arctan (and then the other trig functions as well).

Armed with that info, you could for example create a (database) view doing these calculations.

Then it's simply a matter of creating a master on that view and TABLEing away.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Platinum Member
posted Hide Post
Wep5622 - My kVArh and kWh numbers are coming from a Hive database. I can check around to see if there is an implementation of these functions for HIve. However, as I understand the Hive database will not support database view. Also, not sure if I can use SQL pass-thru to execute it though if there are implementation of these functions.

So do you know how this calculation applies that was posted in 2007:

A_TAN2(y,x)= (y/x) - (((y/x) ** 3)/3)
+ (((y/x) ** 5)/5)
- (((y/x) ** 7)/7)
+ (((y/x) ** 9)/9)
- (((y/x) ** 11)/11)
+ (((y/x) ** 13)/13);


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Gold member
posted Hide Post
AMC,

It seems that an arctan function is something people want every few years, and so after some research, I wrote an atan defined function that should do the trick. This particular algorithm is accurate to about 14 digits, which should be adequate for any commercial application. *** BEWARE *** the routine has not been comprehensively tested so use it after your own testing and at your own risk.
DEFINE FUNCTION ATAN(XVAL/D12.2)
-* see pdf "A Guide to Approximations" Jack G. Ganssle 2001
PI/D20.18   =  3.141592653589793 ;
PIO6/D20.18 =  .5235987755982989 ;
PIO12/D20.18 = .2617993877991494 ;
TANPI6/D20.18= .5773502691896258 ;
TANPI12/D20.18=.2679491924311227 ;

-* first, reduce the input to <= pi/12
SIGN/I1 = IF XVAL LT 0 THEN 1 ELSE 0 ;
XVAL = IF XVAL LT 0 THEN -XVAL ;
COMPL/I1 = IF XVAL GT 1.0 THEN 1 ELSE 0 ;
XVAL = IF XVAL GT 1.0 THEN 1.0/XVAL ;
REGION/I1 = IF XVAL GT TANPI12 THEN 1 ELSE 0;
XVAL = IF XVAL GT TANPI12 THEN
       (XVAL-TANPI6)/(1.0+(TANPI6*XVAL)) ;

D1= 48.70107004404898;
D2= 49.53262637722543;
D3= 9.40604244231624;
D4= 48.701070044049962;
D5= 65.76631639089563;
D6= 21.587934067020262;
XSQ = XVAL * XVAL ;

-* now, compute the arc tangent
ATAN/D12.8 = (XVAL*(D1 +XSQ*(D2 + XSQ*D3))/(D4 + XSQ*(D5 + XSQ*(D6 + XSQ))));

-* finally, adjust for sign, region, and complement
ATAN = IF REGION THEN ATAN+PIO6 ;
ATAN = IF COMPL THEN PI/2.0 - ATAN ;
ATAN = IF SIGN THEN -ATAN ;
END
 


Enjoy.


IBI Development
 
Posts: 61 | Registered: November 15, 2005Report This Post
Platinum Member
posted Hide Post
Edward Wolfgram - Thanks. I can add these to the others I have on the reporting server and test it. Thanks a lot....much appreciate it.


WF 8.1.05
Windows
SQL Server 2014
HTML, PDF, EXCEL
 
Posts: 175 | Registered: March 24, 2017Report This Post
Virtuoso
posted Hide Post
quote:
Originally posted by AMC:
Wep5622 - My kVArh and kWh numbers are coming from a Hive database. I can check around to see if there is an implementation of these functions for HIve. However, as I understand the Hive database will not support database view. Also, not sure if I can use SQL pass-thru to execute it though if there are implementation of these functions.


Ah, we can scratch that option off the list then...

quote:
So do you know how this calculation applies that was posted in 2007:

A_TAN2(y,x)= (y/x) - (((y/x) ** 3)/3)
+ (((y/x) ** 5)/5)
- (((y/x) ** 7)/7)
+ (((y/x) ** 9)/9)
- (((y/x) ** 11)/11)
+ (((y/x) ** 13)/13);


That looks like a Taylor polynome. Those are approximations, but the more components you add, the more accurate they become.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
quote:
DEFINE FUNCTION ATAN(XVAL/D12.2)

One for the collection Wink Thanks Edward!!

For anyone using Edward's function, remember that it returns a value in Radians not Degrees - but getting the Degrees - that's the easy bit.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Expert
posted Hide Post
Trying to run a quick proof to set how accurate the functions are and I realised that the Sine and Cosine functions do not match what I use because you have to apply a fix for angles above 180 degrees.

To see what I mean, use the functions from Michael above add -RUN after the declaration of the functions and then add this code to chart the results from the functions for a full 360 degree spread.

You will see that the Sine and Tangent results are wrong.

EX -LINES * EDAPUT MASTER,TRIGDATA,CV,MEM
FILE=TRIGDATA,SUFFIX=FOC
SEGNAME=SEG1
FIELD=ANGLE,   ,I3   ,I3   , $
EDAPUT*
-RUN

CREATE FILE TRIGDATA
MODIFY FILE TRIGDATA
FIXFORM ANGLE/A3
DATA
-REPEAT :Loop FOR &Angle FROM 1 TO 360;
&Angle
-:Loop
END
-RUN

GRAPH FILE TRIGDATA
PRINT COMPUTE SINE/D12.10 = F_SIN(ANGLE);
      COMPUTE COSINE/D12.10 = F_COS(ANGLE);
      COMPUTE TANGENT/D12.10 MISSING ON = IF F_TAN(ANGLE) GT  2 THEN MISSING
	                                 ELSE IF F_TAN(ANGLE) LT -2 THEN MISSING ELSE F_TAN(ANGLE);
   BY ANGLE
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET VZERO OFF
ON GRAPH SET AUTOFIT ON
ON GRAPH SET HTMLENCODE ON
ON GRAPH SET GRAPHDEFAULT OFF
ON GRAPH SET GRMERGE ADVANCED
ON GRAPH SET GRMULTIGRAPH 0
ON GRAPH SET GRLEGEND 0
ON GRAPH SET GRXAXIS 1
ON GRAPH SET LOOKGRAPH VLINE
ON GRAPH SET STYLE *
*GRAPH_SCRIPT
setPieDepth(0);
setPieTilt(0);
setDepthRadius(0);
setCurveFitEquationDisplay(false);
setPlace(true);
setUseSeriesShapes(false);
setMarkerSizeDefault(25);
setReportParsingErrors(false);
setSelectionEnableMove(false);
setTransparentBorderColor(getSeries(*), false);
setDisplay(getO1Title(),false);
setDisplay(getY1Title(),false);
setFillColor(getSeries(0),new Color(0,128,0));
setFillColor(getSeries(1),new Color(255,128,0));
setFillColor(getSeries(2),new Color(237,186,4));
setFillColor(getSeries(3),new Color(186,4,237));
setY1ScaleMin(-2);
setY1ScaleMax(2);
*END
ENDSTYLE
END


T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Virtuoso
posted Hide Post
I suppose an easy fix for F_SIN is to express it in terms of F_COS with a phase-shift:
DEFINE FUNCTION F_SIN(angle/D8.5)
F_SIN/D31.25 = F_COS(angle - 90);
END


Similarly, you can use the fact that TAN alpha = SIN alpha / COS alpha, where the TAN goes to +/- infinity when COS alpha = 0.

In fact, the posted code already does so, but it first re-defines the computation of F_COS and partially F_SIN.

Quite possibly there was a good reason to do so, but you can write it as simply:
DEFINE FUNCTION F_TAN(angle/D8.5)
COSIN/D31.25 = F_COS(angle); 
SIN/D31.25 = F_SIN(angle); 
F_TAN/D31.25 MISSING ON = IF COSIN EQ 0 THEN MISSING ELSE SIN/COSIN;
END


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
Continued ...

To correct these errors is easy just modify the result depending upon the angle or use per Wep above.

Instead of repeating the code from the Cosine function in the Sine and Tangent functions you could just call the F_COS function. Of course, the F_COS function would need to be defined before the F_SIN or F_TAN.

DEFINE FUNCTION F_SIN(angle/D8.5)
  F_SIN/D31.25  = F_COS(angle - 90) ;
END

DEFINE FUNCTION F_TAN(angle/D8.5)
  COSIN/D31.25  = F_COS(angle) ;
  SIN/D31.25    = F_SIN(angle) ;
  F_TAN/D31.25  = SIN / COSIN;
END


I am having difficulties uploading an image to my webspace but, when I am able, I will post an image showing before and after.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Virtuoso
posted Hide Post
While looking into this, I was playing around with turning PI into a function so that it could easily be referenced, but it appears that FOCUS functions require at least one parameter and that makes the result a little ugly:
DEFINE FUNCTION PI(DUMMY/I1)
PI/D31.29 = 3.14159265358979;
END

TABLE FILE TRIGDATA
PRINT COMPUTE PI/D12.11 = PI(0);
IF READLIMIT EQ 1
END


I tried using LET PI = 3.14159265358979;, but that caused an error in the definition of F_COS: (FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: PI

It would be nice if there were a DEFINE CONSTANT PI/D31.29 = 3.14159265358979 or something similar.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Expert
posted Hide Post
You could use a global variable but may have to use the SET DMPRECISION. As that only allows a maximum of 9 decimals that might be a limitation Frowner

Wonder if you could get a restful call to something like piday.org Wink

T

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Need to Compute Trigonometric Function

Copyright © 1996-2020 Information Builders