943,946 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 347
  • C++ RSS
Nov 1st, 2009
0

Calling Functions

Expand Post »
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);
Last edited by jhanthem; Nov 1st, 2009 at 7:32 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhanthem is offline Offline
3 posts
since Oct 2009
Nov 1st, 2009
0
Re: Calling Functions
cant you just do this :
C++ Syntax (Toggle Plain Text)
  1. void xSinX(int * A, int SZ, int lim){
  2. for(int i = 0; i < lim && i < SZ; i++){
  3. A[i] = i*sin( float(i) ); //xsin(x)
  4. }
  5. }
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,864 posts
since Dec 2008
Nov 2nd, 2009
0
Re: Calling Functions
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]); ?
Reputation Points: 1268
Solved Threads: 228
Posting Virtuoso
vmanes is offline Offline
1,895 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I need some help.
Next Thread in C++ Forum Timeline: what does single quote means ??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC