# Thread: Need help for solving a function.

1. ## Need help for solving a function.

How can I multiply x with y? I mean I have to find AREA between function line and X-Axis.

Exercise is like this:
Function: y=tan(x/2) -> tan(x/2)
Determination area: 0,2<x<1,55

Code:
```#include<stdio.h>
#include<math.h>
#include<conio.h>

int main()
{
float x,y,sum;

for(x=0.2; x<1.55;x*tan(x/2)){
x = x + 0.0135*(x*tan(x/2));
y =tan(x/2);
sum=
printf("%f %f\n",x,y);
}
_getch();
return 0;

}``` 2. Originally Posted by peppeNzjik How can I multiply x with y?
Code:
`z = x * y;`

Quzah. 3. Originally Posted by quzah Code:
`z = x * y;`

Quzah.
Yeah, I understand that, but when it prints x and y, then x is from 0.36 to 1.56 and y is 0.18 to 0.99.

I need to sum all numbers in X column and all numbers in Y column. How can I do it when there are so many numbers in one column? 4. Can you be more clear? Do you want to multiply 'x' and 'y' before, during, or after you sum their column of values?

I need to sum all numbers in X column and all numbers in Y column. How can I do it when there are so many numbers in one column?
Like this?

Code:
```float x,y;
float x_sum = 0;
float y_sum = 0;

loop()
{
// do stuff to 'x'
x_sum += x;
// do stuff to 'y'
y_sum += y;
}``` 5. So you are looking for the integral of the function, the area under the curve?

It appears you are approximating it as a series of rectangles.
In that case you want to multiply each value of y by the step size of x.
And these individual areas (y * step size of x) are added up.

I believe you only want to increment x by 0.0135 each time through the loop:
(I'm guessing that 0.0135 is the step size you want to use)

x = x + 0.0135;

not all this:

x = x + 0.0135*(x*tan(x/2));

You are trying to accumulate the sum in x. You need to accumulate the sum in 'sum':

sum = sum + 0.0135*y; 6. The reason x isn't printing out with it's starting value of 0.2 is that you are modifying it from it's starting value
before you are printing it out.

Also some suggestions:

Initialize 'sum' to 0 before the loop begins.

In the "for" statement:

for(x=0.2; x<1.55;x*tan(x/2),

this part "x*tan(x/2)" doesn't do anything. What you should put here is the increment of the x variable: x = x+0.0135, and remove the increment of x
from the body of the loop. The print statement will also output the value of x as you expect, since x will not be incremented until the end of the loop. 7. Originally Posted by megafiddle So you are looking for the integral of the function, the area under the curve?

It appears you are approximating it as a series of rectangles.
In that case you want to multiply each value of y by the step size of x.
And these individual areas (y * step size of x) are added up.

I believe you only want to increment x by 0.0135 each time through the loop:
(I'm guessing that 0.0135 is the step size you want to use)

x = x + 0.0135;

not all this:

x = x + 0.0135*(x*tan(x/2));

You are trying to accumulate the sum in x. You need to accumulate the sum in 'sum':

sum = sum + 0.0135*y;
This is exactly what I mean. 8. Your program only needs those few changes.
Have you tried fixing it up?

Post a corrected version of it, and it should be simple to get it working from there. Popular pages Recent additions 