Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8. double f(double x,double y,double z){
  9.     return (z*y+x);
  10. }
  11.  
  12. double g(double x,double y,double z){
  13.     return (z*x+y);
  14. }
  15.  
  16.  
  17.  
  18.  
  19. void rungeKuta2equacoes(double x0,double y0,double z0, double h,double lim,double &yn,double &zn){
  20.     double xn=x0;
  21.     yn=y0;
  22.     zn=z0;
  23.     int n=(lim-x0)/h;
  24.  
  25.  
  26.     do{
  27.         x0=xn;
  28.         y0=yn;
  29.         z0=zn;
  30.         double d1= h*f(x0,y0,z0);
  31.         double k1= h*g(x0,y0,z0);
  32.         double d2= h*f(x0 + (h/2),yn + d1/2,z0 + (k1/2));
  33.         double k2= h*g(x0+(h/2),y0+(d1/2),zn + (k1/2));
  34.         double d3= h*f(x0+(h/2),yn+(d2/2),zn + (k2/2));
  35.         double k3= h*g(x0+(h/2),y0+(d2/2),z0+(k2/2));
  36.         double d4= h*f(x0+h,yn+d3,z0+k3);
  37.         double k4= h*g(x0+h,y0+d3,z0+k3);
  38.         xn = x0+h;
  39.         yn = y0+(d1/6)+(d2/3)+(d3/3)+(d4/6);
  40.         zn = z0+(k1/6)+(k2/3)+(k3/3)+(k4/6);
  41.         n--;
  42.     }while(n>=0);
  43.  
  44.     cout << "Syn-> " << yn << endl;
  45.     cout << "Szn-> " << zn << endl;
  46. }
  47.  
  48.  
  49. /*
  50. int main(){
  51.     double syn;
  52.     double s1yn;
  53.     double s2yn;
  54.     double szn;
  55.     double s1zn;
  56.     double s2zn;
  57.  
  58.  
  59.     cout << "S" << endl;
  60.     rungeKuta2equacoes(0,1,1,0.1,0.5,syn,szn);
  61.     cout << endl << "S`:" << endl;
  62.     rungeKuta2equacoes(0,1,1,(0.1/2),0.5,s1yn,s1zn);
  63.     cout << endl << "S``:" << endl;
  64.     rungeKuta2equacoes(0,1,1,(0.1/4),0.5,s2yn,s2zn);
  65.  
  66.     cout << endl << "Qcyn-> " << (s1yn-syn)/(s2yn-s1yn) << endl;
  67.     cout << "Qczn-> " << (s1zn-szn)/(s2zn-s1zn) << endl;
  68.     cout << "Eyn-> " << (s2yn-syn)/15 << endl;
  69.     cout << "Ezn-> " << (s2zn-szn)/15 << endl;
  70.  
  71.     return 0;
  72. }
  73. /**/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement