Results 1 to 2 of 2
 03052013, 04:23 PM #1Member
 Join Date
 Jan 2013
 Posts
 5
 Rep Power
 0
Creating Taylor Series (Different from one in search) Having so much trouble!
I'm having trouble and seem to have hit a roadblock.
I'm going to copy and paste my question so you know exactly what I'm trying to do and then, I will post my code as of now below that:
QUESTION:
Writing the sin(x) method (50 points)
Write a method called sin that takes as input a double and returns a double. Should approximate using taylor series.
You may not use any library method (such as Math.pow) for this.
You must use at least one loop in your method.
Note: The approximation will only be close to the actual value with a=10 for small values of x (between 1 and 1).
You should not use Scanner or have print statements in any of the required methods with the exception of System.out.println statements being allowed inside of the main method of part 2a.
Here is my code:
Java Code://x = User Input Number //Function: x  (x^3/3!) + (x^5/5!)  (x^7/7!) ..>.. + (x^21/(21!) :@: import java.util.Scanner; public class TaylorSin { public static final double a = 10.0; public static void main(String[] args) { Scanner UserInput = new Scanner(System.in); System.out.println("Please enter a number between 1 and +1"); double x = UserInput.nextDouble(); System.out.println("Your inputed number was" + x + "."); System.out.println(Numerator() / Factorial() ); } public static double Numerator(double x){ //The Numerator formula double power = 1.0; double sum = 0.0; double individualNumerator = (x^power); do{ sum += individualNumerator; } while (power <= 21); power += 2; return sum; } public static double factorial(){ //The Denominator formula double result = 1; for(int i = 1; i <= x; ++2) { result *= i; } return result; } }
1. How to I do the ADD (1st element of function ie. x) SUBTRACT (2nd element of function ie. x^3/3!) ... and so forth until I reach 21.
2. Should I calculate each function element as (numerator/denominator) and how would I go about this followed by (the addition/subtraction) of each element
3. Am I doing anything blatantly wrong or misguided towards my final answer of creating the sin function?
NOTE: I'm not comfortable with arrays as we just started them, but if it would make it easier let me know.
NOTE: Any help is gratefully appreciated as my assignment is due tonight at 11:59 PM EST.
Thank you so much,
I'm here to learn so tips are appreciated, I don't want you to solve my assignment for me.
 03052013, 04:39 PM #2Senior Member
 Join Date
 Jan 2013
 Location
 Northern Virginia, United States
 Posts
 6,226
 Rep Power
 14
Re: Creating Taylor Series (Different from one in search) Having so much trouble!
Well, as far as alternate addition and subtraction, you could write your own method to raise a value to a specific power. Then use that method in conjunction with the fact that 1 raised to consecutive integral powers alternates its sign.
Edit: I was looking over this again and spotted a major error. The caret symbol (^) is not exponentiation. It is an eXclusive OR operation. To do exponentiation you must use the Math.pow() method which your professor has declared off limits.
Regards,
JimLast edited by jim829; 03052013 at 06:16 PM. Reason: noticed exponentiation problem
The Java^{TM} Tutorials  SSCCE  Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads

Trouble with creating Method and functionality for multiplying a polynomial
By bradoz in forum New To JavaReplies: 17Last Post: 03282012, 08:29 AM 
trouble creating stack using array
By shashankc in forum New To JavaReplies: 5Last Post: 01202011, 12:49 PM 
Trouble creating object that includes array
By Desdenova in forum New To JavaReplies: 7Last Post: 05182010, 07:33 PM 
Trouble with creating TreeSet
By MrKP in forum New To JavaReplies: 1Last Post: 12272009, 02:22 AM 
Trouble with a search hw problem.
By frasifrasi in forum New To JavaReplies: 3Last Post: 07102008, 09:26 PM
Bookmarks