Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. #define E 2.7182818284590452353
  5.  
  6. using namespace std;
  7.  
  8. double ket = 0.365 / 60, vap = 3250, ke = ket / vap;
  9.  
  10.  
  11. double f(double ka){
  12.     double tmax = 1.6 / 60.0;
  13.     return ka*pow(E, -ka*tmax) - ket*pow(E, -ket*tmax);
  14. }
  15.  
  16. //Método da bisseção
  17.  
  18. double bissec(double a, double b){
  19.  
  20.     double h = 0;
  21.  
  22.  
  23.     while (h < 1000){
  24.         double m = (a + b) / 2.0;
  25.         if (f(a)*f(m) < 0){
  26.             b = m;
  27.         }
  28.         else a = m;
  29.         h++;
  30.     }
  31.     return b;
  32. }
  33.  
  34. //Método da corda
  35.  
  36. double corda(double a, double b){
  37.  
  38.     double h = 0;
  39.  
  40.     while (h < 10000){
  41.         double w = (a*f(b) - b*f(a) / (f(b) - f(a)));
  42.  
  43.         if (f(a)*f(w) < 0)
  44.             b = w;
  45.         else a = w;
  46.         h++;
  47.     }
  48.  
  49.     return b;
  50. }
  51.  
  52.  
  53. void main(){
  54.     cout << "zero: " << bissec(0, 0.1) << endl;
  55.     cout << "zero: " << corda(0, 0.1) << endl;
  56.     system("pause");
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement