| | |
Please help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 15
Reputation:
Solved Threads: 0
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
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
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
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."
0
#4 Oct 10th, 2009
Your line:
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:
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.
java Syntax (Toggle Plain Text)
while (i<=k)
java Syntax (Toggle Plain Text)
x=input.nextDouble();
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. ![]() |
Other Threads in the Java Forum
- Previous Thread: Complexity Class Estimate: Big O
- Next Thread: Java Midlet
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class classes click client code compare component coordinates database doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool linux list loop map method methods mobile netbeans newbie nextline oracle pong print problem program programming project recursion recursive rim scanner screen sell server set size sms sort sql string swing threads time tree user web websites windows






