# Thread: Create Math.sin without math.sin

1. Member Join Date
Dec 2010
Posts
6
Rep Power
0

## Create Math.sin without math.sin

I have a homework assignment where it asks me to do this: Java has a "sine"-computing function: Math.sin(#)

I am new to java so please be patient with me and teach me with babysteps. :(

This is what I have:
Java Code:
```mport sdsu.io.*;
public class hw7
{

public static void main(String args[])
{
double x;
System.out.println("Please enter a value for x.");

double maxe;
double[]a =  new double;
for (int i = 0; i <= maxe; i++)
{
a[i] = i;
if ( i %2 !=0);

System.out.println(+a[i]);
}
}

//public static double f(double x) //I'm not sure how to do a summation to represent the sine function. This is as close as I got.
//        {
//        return  x -(Math.pow(x,a)/a) + (Math.pow(x,a/a -
//        (Math.pow(x,a/a);
//        }
//}
}```
I keep getting these errors:
Java Code:
```hw7.java:26: ')' expected
(Math.pow(x,a/a);
^
hw7.java:26: ')' expected
(Math.pow(x,a/a);
^
hw7.java:27: ';' expected
}
^
hw7.java:29: reached end of file while parsing
}
^
5 errors```  Reply With Quote

2. ## The error pointed that you've missing one closing bracket here.

Java Code:
`return  x -(Math.pow(x,a)/a) + (Math.pow(x,a/a - (Math.pow(x,a/a);`
It should be something like this.

Java Code:
`return  x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) - (Math.pow(x,a/a));`
And more clearly,

Java Code:
`return  (x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) - (Math.pow(x,a/a)));`  Reply With Quote

3. Member Join Date
Dec 2010
Posts
6
Rep Power
0

## It seems like I brought out a hellstorm.
Java Code:
```symbol  : variable a
location: class hw7
return  (x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) -
^
hw7.java:25: cannot find symbol
symbol  : variable a
location: class hw7
return  (x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) -
^
hw7.java:25: cannot find symbol
symbol  : variable a
location: class hw7
return  (x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) -
^
hw7.java:25: cannot find symbol
symbol  : variable a
location: class hw7
return  (x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) -
^
hw7.java:26: cannot find symbol
symbol  : variable a
location: class hw7
(Math.pow(x,a/a)));
^
hw7.java:26: cannot find symbol
symbol  : variable a
location: class hw7
(Math.pow(x,a/a)));
^
6 errors```
Did I not code my array correctly?  Reply With Quote

4. ## Could you post the corrected code over here to see, the complete one?  Reply With Quote

5. Member Join Date
Dec 2010
Posts
6
Rep Power
0

## Java Code:
```import sdsu.io.*;
public class hw7
{

public static void main(String args[])
{
double x;
System.out.println("Please enter a value for x.");

double maxe;
double[]a =  new double;
for (int i = 0; i <= maxe; i++)
{
a[i] = i;
if ( i %2 !=0);

System.out.println(+a[i]);
}
}
public static double f(double x)
{
return  (x -(Math.pow(x,a)/a) + (Math.pow(x,a/a)) -
(Math.pow(x,a/a)));
}
}```  Reply With Quote

6. ## You have define the array a in main method. So it's not possible to access it from another method. It's an invalid scope to access. Do you know about variable scope?

If you want to use the same array then you've define them globally. Something like this.

Java Code:
```public class hw7{

private static double[] a = new double;

public static void main(String args[]) {
double x;
System.out.println("Please enter a value for x.");

double maxe;

for (int i = 0; i <= maxe; i++) {
a[i] = i;
if (i % 2 != 0);

System.out.println(+a[i]);
}
}

public static double f(double x) {
return (x - (Math.pow(x, a) / a) + (Math.pow(x, a / a))
- (Math.pow(x, a / a)));
}
}```  Reply With Quote

7. Member Join Date
Dec 2010
Posts
6
Rep Power
0

## No, I do not what a variable scope is, but from what you did, I think I understand what you mean by defining it globally.

Could you please show me how I would be able to do this equation in Java?
Java Code:
```            3         5         7                           maxe
x         x         x                           x
x   -   ---   +   ---   -   ---   +   .......   (+/-)   ---
3!        5!        7!                          maxe!```
(it is in my pastebin link for more clarification, my current equation does not work.)  Reply With Quote

8. ## First of all separate those into to two, numerator and denominator. Just forget about the sign and all. So think how to calculate the term (Y^7 / X!). Did you get my point?

By the way did you know what this equation is, any special kind of name?  Reply With Quote

9. Member Join Date
Dec 2010
Posts
6
Rep Power
0

## I am not sure what you mean by separate them in a numerator and denominator.
Java Code:
```
(Math.pow(x, a) / a)
^               ^
Numerator         Denominators```
Is that not correct? Also is it called a summation right?  Reply With Quote

10. Member Join Date
Dec 2010
Posts
6
Rep Power
0

## Would this be correct to represent the equation above?
Java Code:
```(x - (Math.pow(x, a) / a*a*a*a) + (Math.pow(x, a /
a*a*a*a*a*a))
- (Math.pow(x, a / a*a*a*a*a*a*a*a)));```  Reply With Quote

11. ##  Originally Posted by vudoo I am not sure what you mean by separate them in a numerator and denominator.
Java Code:
```
(Math.pow(x, a) / a)
^               ^
Numerator         Denominators```
Is that not correct? Also is it called a summation right?

What I mean, numerator is simply power of a digit. That's could be narrow down into multiplication.

eg: x ^ 5 = x * x * x * x * x;

Denominator is factorial of a number. That is x! = x * (x -1) * ..... * 1;

Actually what you are going to deals with is a standard number manipulation. The following article explain it, if you could try to understand it. So it may helpful to you, to solve the problem.  Reply With Quote

12. ##  Originally Posted by vudoo Would this be correct to represent the equation above?
Java Code:
```(x - (Math.pow(x, a) / a*a*a*a) + (Math.pow(x, a /
a*a*a*a*a*a))
- (Math.pow(x, a / a*a*a*a*a*a*a*a)));```
Looks to me this is too complex. And I'm sure you are in trouble when you look at this again at a later time.

Don't implement such complex calculations in a single statement. And also don't write complex statements in return. Step-down it. Look at my previous post.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•