Home Random Page


CATEGORIES:

BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism






SOLUTION OF THE TASK OF TERM ASSIGNMENT

The task of my term assignment is the calculation of sin(x) trigonometric function using the continued fraction method via DL representation of codes.

The sin(x) function may be represented by the Taylor’s series in following form:

So the task is to calculate the given sum by using this formula. Let the number of iterations n = 10. The source code of solution is:

#include "DLClass.h"

 

int main()

{

//the goal is to realize the function calculating sinx

 

double x=1.57; // the argument of the function x;

double factorial=1.0;// here we calculate the factorial

double sign=-1.0;//the sign

 

A1 numerator;

A1 denominator;

A1 sum=0.0;

A1 sign_DL;

A1 arg=x;

 

for(int n=0;n<10;n++)

{

//the numerator calculation

sign=-1.0;

sign=pow(sign,n);

sign_DL=sign;

numerator=x;

for(int i=1;i<2*n+1;i++)

{

numerator=numerator*arg;

}

numerator=numerator*sign_DL;

//the denominator calculation;

factorial=1.0;

for(int i=1;i<=2*n+1;i++)

{

factorial*=i;

}

denominator=factorial;

 

//now the sum is calculated

sum=sum+numerator/denominator;

}

 

char buf[256];

sum.ToString(buf);

printf("%s\n",buf);

return 1;

}

This code computes the sin(x) of 1.57 that is approximately pi over 2.

The result is (fig.5.1):

Figure 5.1. Snapshot of result.

It’s obvious that simple transformation of this code allows the calculation of sinus function of any input argument with any number of iterations.

Calculations of such accuracy are impossible without using the DL codes.

 

Conclusion.During the execution of current term assignment we have learned the principles of operation and utilization of Digital Logarithmic Data representation. We have developed the convenient reliable C++ class describing DL arithmetic that can be used for calculations of any complexity. The task was to perform the example of high-accuracy calculations via DL. My task was the calculation of trigonometric function. Actually, the obtained results are more higher accurate than one can obtain by using standard means of C++ calculations and standard data types. Furth more, the developed class is good scalable – a lot of functions can be easily added by using already written ones: for example the function calculating sin(x) may be rewritten as the public method of this class. In such manner the logical and data-conversion methods can be added to. If such work is performed – the totally tested class may be incorporated into COM object and be redistributed for being used in any application written on the .NET platform.

 

 


Date: 2015-12-24; view: 747


<== previous page | next page ==>
Models of Data Structures in the Main Memory | Federal Agencies and Consumerism
doclecture.net - lectures - 2014-2024 year. Copyright infringement or personal data (0.007 sec.)