Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.math.complex.Complex;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Zuzia
- */
- public class Rozwiazanie
- {
- public double E;
- public double Czest;
- public double Faza;
- public double R1;
- public double R2;
- public double C;
- public double L;
- public double tpocz=1;
- public double tkon=20;
- public int opcja = 0;
- public class RozniczkaUcStO implements Rownanie
- {
- public double rozniczka(double t, double uc, double il)
- {
- //System.out.println("L to:"+L);
- return 1.0/L*uc;
- }
- }
- public class RozniczkaUlStO implements Rownanie
- {
- public double rozniczka(double t, double uc, double il)
- {
- return 1.0/L*uc;
- //return Math.cos(t);
- }
- }
- public class RozniczkaUcStZ implements Rownanie
- {
- public double rozniczka(double t, double uc, double il)
- {
- return 5*Math.sin(t*2);
- //return 1.0/L*uc;
- //return Math.cos(t);
- }
- }
- public class RozniczkaUlStZ implements Rownanie
- {
- public double E(double t)
- {
- return E*Math.sin(t*2*Math.PI*Czest+Faza);
- }
- public double rozniczka(double t, double uc, double il)
- {
- return (1.0/C)*(E(t)/R1 +(1/R1-1/R2)*uc -il);
- //return Math.cos(t);
- }
- }
- public class RozniczkaUcZmO implements Rownanie
- {
- public double rozniczka(double t, double uc, double il)
- {
- //System.out.println("L to:"+L);
- return 1.0/L * uc;
- }
- }
- public class RozniczkaUlZmO implements Rownanie
- {
- public double rozniczka(double t, double uc, double il)
- {
- return -1.0/L*uc;
- }
- }
- public class RozniczkaUcZmZ implements Rownanie
- {
- public double E(double t)
- {
- return E*Math.sin(t*2*Math.PI*Czest+Faza);
- }
- public double rozniczka(double t, double uc, double il)
- {
- return -(1.0/C)*(E(t)/R1 +(1/R1-1/R2)*uc -il);
- }
- }
- public class RozniczkaUlZmZ implements Rownanie
- {
- public double rozniczka(double t, double uc, double il)
- {
- return 1.0/L*uc;
- }
- }
- public Rownanie dUc = null;//new RozniczkaUcO();
- public Rownanie dIl = null;//new RozniczkaUlO();
- public void policzWartosci()
- {
- Complex e = new Complex( Math.cos(Faza)*E, Math.sin(Faza)*E);
- Complex zL = new Complex(0, 2*Math.PI*Czest*L);
- Complex zC = new Complex(0, -1*2*Math.PI*Czest*C);
- Complex Zr1 = new Complex(R1,0);
- Complex Zr2 = new Complex(R2,0);
- Complex jeden = new Complex(1,0);
- Complex dodajR = jeden.divide(Zr1).add(jeden.divide(Zr2));
- Complex dodajZ = jeden.divide(zL).add(jeden.divide(zC));
- Complex licznik = new Complex(e.getReal(),e.getImaginary());
- Complex mianownik = Zr1.multiply(dodajR.add(dodajZ));
- Complex V =licznik.divide(mianownik);
- Il =V.divide(zL);
- Uc =V;
- }
- public Complex Il;
- public Complex Uc;
- public double [][]generujPrzebiegUstalonyIl(double tp, double tk, int stepnr)
- {
- double dt = (tk-tp)/stepnr;
- double [][]wynik = new double [2][stepnr];
- double t=tp;
- double przesfaz = Math.atan(Il.getImaginary()/Il.getReal());
- for(int i=0; i<stepnr; i++)
- {
- t = i*dt+tp;
- wynik[0][i]=t;
- wynik[1][i]=Math.sin(2*Math.PI*t+przesfaz);
- }
- return wynik;
- }
- public double [][]generujPrzebiegUstalonyUc(double tp, double tk, int stepnr)
- {
- double dt = (tk-tp)/stepnr;
- double [][]wynik = new double [2][stepnr];
- double t=tp;
- double przesfaz = Math.atan(Uc.getImaginary()/Uc.getReal());
- for(int i=0; i<stepnr; i++)
- {
- t = i*dt+tp;
- wynik[0][i]=t;
- wynik[1][i]=Math.sin(2*Math.PI*t+przesfaz);
- }
- return wynik;
- }
- public double[][] RunggeCutty(int n, double xp, double xk, double y0, double uc0, double il0)
- {
- Rownanie [] rozn = new Rownanie[2];
- switch (opcja) {
- case 0:
- dUc = new RozniczkaUcStO();
- dIl = new RozniczkaUlStO();
- break;
- case 1:
- dUc = new RozniczkaUcZmO();
- dIl = new RozniczkaUlZmO();
- break;
- case 2:
- dUc = new RozniczkaUcStZ();
- dIl = new RozniczkaUlStZ();
- break;
- case 3:
- dUc = new RozniczkaUcZmZ();
- dIl = new RozniczkaUlZmZ();
- break;
- }
- rozn[0] = dUc;
- rozn[1] = dIl;
- int step =4; // RK4
- double h = (xk - xp) / n;
- //XYSeries[][] y = new XYSeries[rozn.length][n]; // wektor rozwiązań
- double[][] y = new double[rozn.length+1][n]; // wektor rozwiązań
- double[] w = new double[] { 1.0/6.0, 1.0/3.0, 1.0/3.0, 1.0/6.0 }; //współczynniki w dla RK4
- double[] k = new double[step]; // k
- double x = xp; //wartosc poczatkowa dla zmiennych stanu
- //for (int i = 0; i < rozn.length; i++) {
- y[0][0] = xp;
- y[1][0] = uc0;
- y[2][0] = il0;
- //}
- for (int i = 1; i < n; i++) {
- y[0][i] = i*h+xp;
- for(int j=1; j<rozn.length; j++)
- {
- k[0] = h*rozn[j].rozniczka(y[0][i-1], y[1][i-1], y[2][i-1]);
- k[1] = h*rozn[j].rozniczka(y[0][i-1]+0.5*h, y[1][i-1]+0.5*k[0], y[2][i-1]+0.5*k[0]);
- k[2] = h*rozn[j].rozniczka(y[0][i-1]+0.5*h, y[1][i-1]+0.5*k[1], y[2][i-1]+0.5*k[1] );
- k[3] = h*rozn[j].rozniczka(y[0][i-1]+h, y[1][i-1]+k[2],y[2][i-1]+k[2] );
- y[j][i] = y[j][i-1];
- for (int z = 0; z < step; z++) {
- y[j][i] += w[z]*k[z];
- }
- }
- }
- return y ;
- }
- }
Add Comment
Please, Sign In to add comment