0

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[0]= 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 [0]=  min + increment*i;
       
   results[0]= x * sin (x);

Edited by jhanthem: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vmanes
0

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)
  }
}
0

results[0]= 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]); ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.