Advertisement
crimeiaman

Runge-Kutta 4th order with 2th order ODE

Sep 16th, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1.  public double onCalculo(int iteracao){
  2.  
  3.         resistorf = Double.parseDouble(resistor.getText().toString());
  4.         capacitorf = Double.parseDouble(capacitor.getText().toString());
  5.         indutorf = Double.parseDouble(indutor.getText().toString());
  6.         tensaof = Double.parseDouble(tensao.getText().toString());
  7.         correntef = Double.parseDouble(corrente.getText().toString());
  8.         tempof = Double.parseDouble(tempo.getText().toString());
  9.  
  10.         //Transformar miliFarad em Farad
  11.         capacitorf=capacitorf/1000;
  12.         //Calcular o passo
  13.         h=tempof/iteracao;
  14.         //Calcular o Valor Inicial de v'(0)
  15.         wf=(-1)*((tensaof+(resistorf*correntef))/(resistorf*capacitorf));
  16.         //Atribuir variaveis secundarias
  17.         hX=h;
  18.         wT=wf;
  19.         tensaofSec=tensaof;
  20.  
  21.         //Atribuir as funcoes das EDO's
  22.         funcaoW=(-1)*((wT/(resistorf*capacitorf))+(tensaofSec/(indutorf*capacitorf)));
  23.         funcaoV=wTV;
  24.  
  25.         for(int i=0;i<iteracao;i++, hX+=h){
  26.  
  27.             tensaofSec=tensaof;
  28.             wTV=wf;
  29.             wT=wf;
  30.  
  31.             //Runge-Kutta para a funcao v'(t) e w'(t)
  32.  
  33.             l1=h*funcaoV;
  34.             k1=h*funcaoW;
  35.  
  36.             wT=(wf+(k1/2));
  37.             wTV=(wf+(k1/2));
  38.             tensaofSec=(tensaof+(l1/2));
  39.  
  40.             k2=h*funcaoW;
  41.             l2=h*funcaoV;
  42.  
  43.             wT=(wf+(k2/2));
  44.             wTV=(wf+(k2/2));
  45.             tensaofSec=(tensaof+(l2/2));
  46.  
  47.             k3=h*funcaoW;
  48.             l3=h*funcaoV;
  49.  
  50.             wT=(wf+k3);
  51.             wTV=(wf+k3);
  52.             tensaofSec=(tensaof+l3);
  53.  
  54.             k4=h*funcaoW;
  55.             l4=h*funcaoV;
  56.  
  57.             wf=wf+((k1+(2*k2)+(2*k3)+k4)/6);
  58.  
  59.             tensaof=tensaof+((l1+(2*l2)+(2*l3)+l4)/6);
  60.         }
  61.         return tensaof;
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement