Please help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 15
Reputation: kulrik is an unknown quantity at this point 
Solved Threads: 0
kulrik kulrik is offline Offline
Newbie Poster

Please help

 
-1
  #1
Oct 10th, 2009
Homework help

Up Vote 0 Down Vote
#1
24 Minutes Ago | Add to kulrik's Reputation | Flag Bad Post
Im having trouble with this problem:

The Maclaurin series for arctan(x) is a formula which allows us to compute an approximation to arctan(x) as a polynomial in x. The formula is:

arctan(x) = x - x3/3 + x5/5 - x7/7 + x9/9 - x11/11 + . . .

Write a method called calculateArctan in the class Mymath . The method reads in a double x, and a positive integer k, and prints out the partial sum from the first k terms in this series. Write a main method to test the method calculateArctan.

Sample output

Enter x:
0.5
Enter integer k:
3
The partial sum from the first k terms: 0.4645833333333333

The arctan of 0.5 : 0.4636476090008061

I started it out and this is all I got:

import java.util.Scanner;


public class MyMath
{
public void calculateArctan()
{

double x;
double sum;
double z;
int i=1;
Scanner input = new Scanner(System.in);
System.out.println("input x");
x=input.nextDouble();
double k;
System.out.println("input k");
z=0;
sum=0;
while (i<=k){

{ sum=sum + Math.pow(x, i)/i;
if(i%2==0)
sum=sum-Math.pow(x,i)/i;

z = z + 1;
}
}//end while
}

public static void main(String[]args)
{
MyMath m;
m = new MyMath();
m.calculateArctan();
}

}//end method

theres alot of errors, and im havin alot of trouble on it, so PLEASE HELP
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso
 
0
  #2
Oct 10th, 2009
Come on, this is already about the third time you post this question, you better spend your time in figuring out a solution to your problem, double posting is not going to help you.

Double posts:
http://www.daniweb.com/forums/thread229171.html
http://www.daniweb.com/forums/post10...ml#post1010429
Last edited by tux4life; Oct 10th, 2009 at 5:49 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 15
Reputation: kulrik is an unknown quantity at this point 
Solved Threads: 0
kulrik kulrik is offline Offline
Newbie Poster
 
0
  #3
Oct 10th, 2009
ive been at it for a week already. im not that good with while loops
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 796
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster
 
0
  #4
Oct 10th, 2009
Your line:
  1. while (i<=k)
is placed before k is properly initialised. I think you need a line inserted to receive the input that you are prompting for. That is similar to your line that reads:
  1. x=input.nextDouble();
but for k instead of x (I'll let you figure that out). Not sure if this is your only error, but it will at least allow your loop to run.

Also, to help us to help you, please describe the error you are receiving, don't just say there are lots of errors as that doesn't really tell us much.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC