[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4786: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4788: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4789: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4790: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
BdMO Online Forum • View topic - Calculating Trigonometric Functions

Calculating Trigonometric Functions

Discuss Computer Science and Programming related problems

Moderators: bristy1588, Labib

Facebook Twitter

Calculating Trigonometric Functions

Post Number:#1  Unread postby amlansaha » Sat Jan 07, 2012 11:43 pm

Write a program to calculate any trigonometric functions(ie. $sin$,$cos$,$tan$ etc).
Please write the alogarithm or the logic. If u code in C/C++, skip using the header file math.h
অম্লান সাহা
User avatar
amlansaha
 
Posts: 100
Joined: Tue Feb 08, 2011 1:11 pm
Location: Khulna, Bangladesh

Re: Calculating Trigonometric Functions

Post Number:#2  Unread postby sm.joty » Sun Jan 08, 2012 12:17 am

:idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea:
আমি নিজে চেষ্টা করে দেখি পারি কিনা। তবে একটা আইডিয়া আসছে, "ম্যাকলরিনের ধারা।"
$sinx=x-\frac{x^3}{3!}+\frac{x^5}{5!}-...............................$
:D
হার জিত চিরদিন থাকবেই
তবুও এগিয়ে যেতে হবে.........
বাধা-বিঘ্ন না পেরিয়ে
বড় হয়েছে কে কবে.........
User avatar
sm.joty
 
Posts: 327
Joined: Thu Aug 18, 2011 12:42 am
Location: Dhaka

Re: Calculating Trigonometric Functions

Post Number:#3  Unread postby amlansaha » Sun Jan 08, 2012 1:12 am

জোত্যিরে তোরে বিশাল ঝাপ্পি
:D :D :D


আমি আসলেই একটা গর্দভ। এইডা যে কেমনে ভুইলা গেলাম :'( :'( :'(
অম্লান সাহা
User avatar
amlansaha
 
Posts: 100
Joined: Tue Feb 08, 2011 1:11 pm
Location: Khulna, Bangladesh

Re: Calculating Trigonometric Functions

Post Number:#4  Unread postby Tahmid Hasan » Sun Jan 08, 2012 10:29 am

দেখে যা মনে হচ্ছে for loop দিয়ে করা যায় বোধহয়।
বড় ভালবাসি তোমায়,মা
User avatar
Tahmid Hasan
 
Posts: 665
Joined: Thu Dec 09, 2010 5:34 pm
Location: Khulna,Bangladesh.

Re: Calculating Trigonometric Functions

Post Number:#5  Unread postby Labib » Sun Jan 08, 2012 3:24 pm

math.h ছাড়া ম্যাক্লরিনের ধারা কেমনে লিখে??
Please Install $L^AT_EX$ fonts in your PC for better looking equations,
Learn how to write equations, and don't forget to read Forum Guide and Rules.


"When you have eliminated the impossible, whatever remains, however improbable, must be the truth." - Sherlock Holmes
User avatar
Labib
 
Posts: 411
Joined: Thu Dec 09, 2010 10:58 pm
Location: Dhaka, Bangladesh.

Re: Calculating Trigonometric Functions

Post Number:#6  Unread postby sabbir.yousuf » Sun Jan 08, 2012 3:33 pm

Write something like -

Code: Select all
double sin(double x) {
    double res = 0;
    int sign = 1;
    double denom = 1;
    double num = x;
    for(i = 1; i <= 100; i+=2) {
        res += (sign * num) / denom;
        num *= (x*x);
        denom *= ((i+1)*(i+2));
        sign *= -1;
    }
    return res;
}
sabbir.yousuf
 
Posts: 6
Joined: Sun Jan 08, 2012 11:43 am

Re: Calculating Trigonometric Functions

Post Number:#7  Unread postby sm.joty » Sun Jan 08, 2012 5:00 pm

math.h ছাড়া ম্যাক্লরিনের ধারা কেমনে লিখে??

আগে একটা ফাংশন বের করতে হবে যেটায় variable পাওয়ার যা, সেটার ফ্যাক্টরিয়াল দিয়ে ভাগ করা হয়।
এবার loop ব্যবহার করে ধারার যোগফল বের করতে হবে। :D

দেখে যা মনে হচ্ছে for loop দিয়ে করা যায় বোধহয়।

আল্গারিদম লিখতে পারলে যেটা খুশি সেটা দিয়েই করা যায়। ;)

Write something like -

double sin(double x) {
double res = 0;
int sign = 1;
double denom = 1;
double num = x;
for(i = 1; i <= 100; i+=2) {
res += (sign * num) / denom;
num *= (x*x);
denom *= ((i+1)*(i+2));
sign *= -1;
}
return res;
}

এর আগা মাথা কিছু বুঝলাম না। কম্পাইল করতে গেলে কম্পাইলার অনেক রকম error দেখায়।
আর res += (sign * num) / denom; এখানে += কি বুঝলাম না ??? একই ভাবে *= কি :?:
আমি প্রোগ্রামিং জগতে নতুন সব ফাংশন জানি না । :( :(
হার জিত চিরদিন থাকবেই
তবুও এগিয়ে যেতে হবে.........
বাধা-বিঘ্ন না পেরিয়ে
বড় হয়েছে কে কবে.........
User avatar
sm.joty
 
Posts: 327
Joined: Thu Aug 18, 2011 12:42 am
Location: Dhaka

Re: Calculating Trigonometric Functions

Post Number:#8  Unread postby sabbir.yousuf » Sun Jan 08, 2012 9:27 pm

Let me explain my code in a more detail

Code: Select all
//we will write a function to calculate sine of a given value
//we will use MacLaurin Series for this purpose
//sinx = x - x^3 / 3! + x^5 / 5! - ......
double sin(double x) {
    double res = 0; //result variable
    int sign = 1; //sign of a particular term in the series, +/-
    double num = x; //num variable will denote the numerator of a particular term in the series
    double denom = 1; //denom variable will denote the denominator of a particular term in the series

    //it's not possible to calculate a infinite sum
    //it's not necessary either because later terms won't contribute much to the sum
    //so we will take first 50 odd terms
    for(int i = 1; i <= 100; i+=2) {
        res += (sign * num) / denom; // 'res += x' means 'res = res + x'
        num *= (x*x); //next numerator, note that each term is x^2 more than the previous one
        denom *= ((i+1)*(i+2)); //next denominator, note that i-th term should be (2*i+1)!
        sign *= -1; //sign alternates in successive terms
    }
    return res;
}
sabbir.yousuf
 
Posts: 6
Joined: Sun Jan 08, 2012 11:43 am

Re: Calculating Trigonometric Functions

Post Number:#9  Unread postby Nadim Ul Abrar » Sun Jan 08, 2012 9:47 pm

মাথার উপর ছাদ । ছাদের উপর আমগাছ । আমগাছের উপর দিয়া যাইতাসে :? :( :cry:
$\frac{1}{0}$
User avatar
Nadim Ul Abrar
 
Posts: 244
Joined: Sat May 07, 2011 12:36 pm
Location: B.A.R.D , kotbari , Comilla

Re: Calculating Trigonometric Functions

Post Number:#10  Unread postby sabbir.yousuf » Sun Jan 08, 2012 10:27 pm

Okay, here's a somewhat simpler and inefficient version -

Code: Select all

double factorial(int n) {
    double res = 1;
    for(int i = 1; i <=n; i++) {
        res = res * n;
    }
    return res;
}

double sin(double x) {
    double res = 0;
    int sign = 1;
    for(i = 1; i <= 100; i+=2) {
        double num = pow(x, i);
        double denom = factorial(i);
        res = res + ((sign * num) / denom);
        sign *= -1;
    }
    return res;
}
sabbir.yousuf
 
Posts: 6
Joined: Sun Jan 08, 2012 11:43 am

Next

Share with your friends: Facebook Twitter

Return to Computer Science

Who is online

Users browsing this forum: No registered users and 1 guest