for the XsineX function I have to calculate xsinx for each value in x then store in result. I need to call on the sin function to do calculations. I tried but I know its completely wrong, any help please??

``````#include <iostream>
#include <cmath>
using namespace std;

// uses Taylor series about x= 0 to find sine also finds limit//
double sine( double x, double tolerance, int & limit ) {
double term = x;
double lastTerm = 0.0;
int i = 1;
do {
term = -(lastTerm * x * x) / ((2 * i) * (2 * i + 1));
lastTerm = term;
i += 1;
}while(fabs(term - lastTerm) > tolerance);
limit = i;
return term;
}

int fillVector( double first, double last, double increment, int size, double data[ ] ) {
int i;
double min, max;
data= min;
for( i = 1; i<size &&data[i-1]<max; i++){
data[i]= data[i-1]+increment;
return i;
}

int xSineX( double x[ ], double result[ ], int size, double tolerance, int limit )
{
int count;
count= (max-min)/increment +1;
for (i=1; i<count; i++){
x =  min + increment*i;

results= x * sin (x);``````

## All 2 Replies

cant you just do this :

``````void xSinX(int * A, int SZ, int lim){
for(int i = 0; i < lim && i < SZ; i++){
A[i] = i*sin( float(i) ); //xsin(x)
}
}``````

`results= x * sin (x);` x is an array - it cannot be used as the operand of a multiplication nor as the argument to sin( ).

Did you mean to say `results[i]= x[i] * sin (x[i]);` ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.