Calling Functions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 3
Reputation: jhanthem is an unknown quantity at this point 
Solved Threads: 0
jhanthem jhanthem is offline Offline
Newbie Poster

Calling Functions

 
0
  #1
26 Days Ago
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; 26 Days Ago at 7:32 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,151
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 145
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Veteran Poster
 
0
  #2
26 Days Ago
cant you just do this :
  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. }
I give up! 
1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e ]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
3) What is the 123456789 prime numer?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso
 
0
  #3
26 Days Ago
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]); ?
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC