Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Help with secant rootfinding

$
0
0
F(X)=X0 - .375X1 + .028125X2 - .0008789X3 + .000012X4

So far i have roots that i found by writing this code:

#include <iostream>
#include <math.h>
using namespace std;
      
      int main(){
             
       float g=9.8;
       float fx;
       float x,x1,x2;
             
       for(x=0;x<5;x=x+.25)
       {
         fx=1 - .375*x + .028125*pow(x,2) - .0008789*pow(x,3) + .000012*pow(x,4);
         if(fx>0&&fx<.05)
         {
           x1=x;
           cout<<x<<"    "<<fx<<endl;
         }
         if (fx<0&&fx>-.05)
         {
           x2=x;
           cout<<x<<"    "<<fx<<endl;
         }
       }
      
      
      
      system("pause");
      }



I got: 3.25 and 3.5, but im supposed to do the secant rootfinding method using this equation

Xi+1 = Xi – (F(Xi)(Xi-1-Xi))/(F(Xi-1) – F(Xi)) Xi-1= x1 = 3.25
Xi= x2 = 3.5

Im confused on what method i should do this in. I think i have the logic figured out, but Im not sure if i should use for loops or not? Any help would be crucial.

Thank you

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>