Thread: need help with sine calculator

  1. #1
    Registered User
    Join Date
    Apr 2014
    Location
    Chandigarh, India, India
    Posts
    4

    need help with sine calculator

    so i got a project from my college to make a calculator including numerous things. everything was done but at the last moment my teacher refused the use of sin() function and asked us to make it manually and not use the sin() function.

    please i need help in creating the new code. with a deadline of less than 24 hours. thank you so much in advance.

    here is the part of code that needs the change, we need to eliminate the use of sin() function.

    r=n1*(M_PI/180);
    v= sin(r);
    printf("%f",v);

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Right. Have you tried searching the Web to find out how it might be implemented? Are you forbidden to use all the trigonometric functions provided in <math.h>?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2014
    Location
    NY
    Posts
    56
    It sounds like hes forbidden from using any type of function to calculate it.

    You need to know how to find sin without a calculator. Then implement the steps to replicate the sin() function.

  4. #4
    Registered User
    Join Date
    Apr 2014
    Posts
    36
    Well, the sine functions are base on the similar triangles concept. I assume that calculators store the value of the ratios of the sine functions of a smaller, easier to work with triangle and then completes a cross multiplication equation to get the final value. for instance, to compute sin(45):

    need help with sine calculator-screen-shot-2014-04-28-12-24-51-pm-png

    The use of this smaller similar triangle will be my example. sine is equal to the opposite over the hypotenuse. Let's say you have a right triangle that had two legs of size 300 and the hypotenuse is 300*√(2). The other two acute angles would still be 45º. So, the sine of those 45º angles would be equal to 300/[300*√(2)]. This can be simplified to 1/[√(2)] which is the sine of the 45 degree angle in the smaller right triangle pictured above. The sin of 45º always has the same value. So, an incredibly long-winded but workable method of creating your own sine function would be to use the unit circle and right in values for all 360º. Or assume that the smallest value of an angle within a right triangle could be 1º, assume the biggest could be 89º, and program default values for those. That's my two cents.

  5. #5

  6. #6
    Registered User
    Join Date
    Apr 2014
    Location
    Chandigarh, India, India
    Posts
    4
    I am restristed to use the sin() function only. I can use math.h ... She recommended using some function series x+1 something. Pls help

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by techie448
    I am restristed to use the sin() function only. I can use math.h
    Well, then a "cheating" method would be to make use of the relationship between sine, cosine and tangent...
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Feb 2014
    Location
    NY
    Posts
    56
    The link africanwizz provided has the sine formula. It even has a step by step example on finding sine. All you need to do is implement the formula into your code.


    Quote Originally Posted by http://www.homeschoolmath.net/teaching/sine_calculator.php
    A calculator or computer program is not reading off of a list, but is using an algorithm that gives an approximate value of sine of a given angle. There are several such algorithms. Many times they only use the four basic operations (+, -, x, /) to find the sine or cosine or tangent of a given angle.
    Last edited by 3DT; 04-28-2014 at 11:09 PM. Reason: added qoute from link

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by techie448 View Post
    She recommended using some function series x+1 something.
    It was probably the Taylor's series. Look at the link given by africanwiz.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #10
    Registered User
    Join Date
    Apr 2014
    Location
    Chandigarh, India, India
    Posts
    4
    hmm looks good. could you write up the code for me implementing the series thing?

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by techie448 View Post
    hmm looks good. could you write up the code for me implementing the series thing?
    Asking for a code hand-out is against the homework policy. Try it yourself, and ask specific questions if you get stuck along the way.

  12. #12
    Registered User
    Join Date
    Apr 2014
    Location
    Chandigarh, India, India
    Posts
    4
    i ain't asking you to do the complete thing. this is a stuck up. i was instructed to design a calc with 20 function. i have done the 19 perfectly but stuck up at this because of some last minutes conditions. and i am completely unaware on how to get this to work can't find it anywhere on the net that is why i asked here.

  13. #13
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by techie448 View Post
    i ain't asking you to do the complete thing. this is a stuck up. i was instructed to design a calc with 20 function. i have done the 19 perfectly but stuck up at this because of some last minutes conditions. and i am completely unaware on how to get this to work can't find it anywhere on the net that is why i asked here.
    Considering that up until post #12, we didn't know there were 19 other functions, we rightfully assumed this was the whole assignment and you were asking us for it. Regardless, you are asking us for "the whole sin function", in that you have provided no evidence that you have put in any effort toward completing this, save posting here asking for free code.

    Besides, even asking us to do one part of your homework is against the policy -- it amounts to academic dishonesty and plagiarism (unless you credit us in your homework, which you probably wouldn't do because your teacher would probably not count that part of the assignment toward your score if you did). We are here to help you learn, not to help you get a grade that you don't deserve because you actually couldn't do the work. You show some real effort, and we'll put in real effort toward helping you get it right. I'll be honest. Your 24 hour deadline (which has probably passed by now) suggests you did not plan your time well, due to laziness or other reasons. I also find your statement that you did the 19 other functions perfectly, but can't figure out a single line of this one and need us to write it all for you, a bit hard to believe; it seems like you're trying to convince us you tried without actually giving any proof, so we give you free code. I hope I'm wrong about those two things. I hope you have genuinely tried, and are truly stuck. If so, you should make a better attempt to prove to us you did your due diligence and put in reasonable effort before asking us for help.

    Give it a honest try if you haven't yet, and post your attempt as a show of good faith that you are trying to do it yourself. Posting some of the code for the other 19 functions, to show you made a decent effort at the assignment as a whole, would also be a sign of good faith on your part.

  14. #14
    Registered User
    Join Date
    Feb 2014
    Location
    NY
    Posts
    56
    Quote Originally Posted by techie448 View Post
    hmm looks good. could you write up the code for me implementing the series thing?
    Absolutely not. This is a very simple task. All you need to do is take the formula change the variables to the ones in your program and play with the order until it calculates the right value of sine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 10-30-2013, 11:34 PM
  2. inverse of sine?
    By xniinja in forum General Discussions
    Replies: 9
    Last Post: 12-16-2011, 10:04 PM
  3. values of sine
    By jacek in forum C Programming
    Replies: 2
    Last Post: 10-31-2009, 04:17 PM
  4. UDF to calculate sine
    By n3cr0_l0rd in forum C Programming
    Replies: 5
    Last Post: 02-26-2009, 08:02 AM
  5. Sine (Sin) Algorithm Help
    By StaticKyle in forum C Programming
    Replies: 52
    Last Post: 05-13-2008, 08:37 AM

Tags for this Thread