Guest User

Untitled

a guest
Jun 20th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1.  
  2. import org.apache.commons.math.complex.Complex;
  3.  
  4.  
  5. /*
  6. * To change this template, choose Tools | Templates
  7. * and open the template in the editor.
  8. */
  9.  
  10. /**
  11. *
  12. * @author Zuzia
  13. */
  14.  
  15.  
  16. public class Rozwiazanie
  17. {
  18.  
  19. public double E;
  20. public double Czest;
  21. public double Faza;
  22. public double R1;
  23. public double R2;
  24. public double C;
  25. public double L;
  26. public double tpocz=1;
  27. public double tkon=20;
  28.  
  29. public int opcja = 0;
  30.  
  31. public class RozniczkaUcStO implements Rownanie
  32. {
  33. public double rozniczka(double t, double uc, double il)
  34. {
  35. //System.out.println("L to:"+L);
  36. return 1.0/L*uc;
  37.  
  38. }
  39. }
  40.  
  41. public class RozniczkaUlStO implements Rownanie
  42. {
  43. public double rozniczka(double t, double uc, double il)
  44. {
  45. return 1.0/L*uc;
  46. //return Math.cos(t);
  47. }
  48. }
  49.  
  50. public class RozniczkaUcStZ implements Rownanie
  51. {
  52. public double rozniczka(double t, double uc, double il)
  53. {
  54. return 5*Math.sin(t*2);
  55. //return 1.0/L*uc;
  56. //return Math.cos(t);
  57. }
  58. }
  59.  
  60. public class RozniczkaUlStZ implements Rownanie
  61. {
  62. public double E(double t)
  63. {
  64. return E*Math.sin(t*2*Math.PI*Czest+Faza);
  65. }
  66.  
  67. public double rozniczka(double t, double uc, double il)
  68. {
  69. return (1.0/C)*(E(t)/R1 +(1/R1-1/R2)*uc -il);
  70. //return Math.cos(t);
  71. }
  72.  
  73. }
  74.  
  75. public class RozniczkaUcZmO implements Rownanie
  76. {
  77. public double rozniczka(double t, double uc, double il)
  78. {
  79. //System.out.println("L to:"+L);
  80. return 1.0/L * uc;
  81.  
  82. }
  83. }
  84.  
  85. public class RozniczkaUlZmO implements Rownanie
  86. {
  87. public double rozniczka(double t, double uc, double il)
  88. {
  89. return -1.0/L*uc;
  90. }
  91. }
  92.  
  93. public class RozniczkaUcZmZ implements Rownanie
  94. {
  95. public double E(double t)
  96. {
  97. return E*Math.sin(t*2*Math.PI*Czest+Faza);
  98. }
  99.  
  100. public double rozniczka(double t, double uc, double il)
  101. {
  102. return -(1.0/C)*(E(t)/R1 +(1/R1-1/R2)*uc -il);
  103. }
  104. }
  105.  
  106. public class RozniczkaUlZmZ implements Rownanie
  107. {
  108.  
  109. public double rozniczka(double t, double uc, double il)
  110. {
  111. return 1.0/L*uc;
  112. }
  113.  
  114. }
  115.  
  116. public Rownanie dUc = null;//new RozniczkaUcO();
  117. public Rownanie dIl = null;//new RozniczkaUlO();
  118.  
  119. public void policzWartosci()
  120. {
  121.  
  122. Complex e = new Complex( Math.cos(Faza)*E, Math.sin(Faza)*E);
  123. Complex zL = new Complex(0, 2*Math.PI*Czest*L);
  124. Complex zC = new Complex(0, -1*2*Math.PI*Czest*C);
  125. Complex Zr1 = new Complex(R1,0);
  126. Complex Zr2 = new Complex(R2,0);
  127. Complex jeden = new Complex(1,0);
  128.  
  129. Complex dodajR = jeden.divide(Zr1).add(jeden.divide(Zr2));
  130. Complex dodajZ = jeden.divide(zL).add(jeden.divide(zC));
  131. Complex licznik = new Complex(e.getReal(),e.getImaginary());
  132. Complex mianownik = Zr1.multiply(dodajR.add(dodajZ));
  133.  
  134. Complex V =licznik.divide(mianownik);
  135. Il =V.divide(zL);
  136. Uc =V;
  137.  
  138.  
  139. }
  140.  
  141. public Complex Il;
  142. public Complex Uc;
  143.  
  144. public double [][]generujPrzebiegUstalonyIl(double tp, double tk, int stepnr)
  145. {
  146. double dt = (tk-tp)/stepnr;
  147. double [][]wynik = new double [2][stepnr];
  148. double t=tp;
  149.  
  150. double przesfaz = Math.atan(Il.getImaginary()/Il.getReal());
  151. for(int i=0; i<stepnr; i++)
  152. {
  153. t = i*dt+tp;
  154. wynik[0][i]=t;
  155. wynik[1][i]=Math.sin(2*Math.PI*t+przesfaz);
  156. }
  157. return wynik;
  158. }
  159.  
  160. public double [][]generujPrzebiegUstalonyUc(double tp, double tk, int stepnr)
  161. {
  162. double dt = (tk-tp)/stepnr;
  163. double [][]wynik = new double [2][stepnr];
  164. double t=tp;
  165.  
  166. double przesfaz = Math.atan(Uc.getImaginary()/Uc.getReal());
  167. for(int i=0; i<stepnr; i++)
  168. {
  169. t = i*dt+tp;
  170. wynik[0][i]=t;
  171. wynik[1][i]=Math.sin(2*Math.PI*t+przesfaz);
  172. }
  173. return wynik;
  174. }
  175.  
  176. public double[][] RunggeCutty(int n, double xp, double xk, double y0, double uc0, double il0)
  177. {
  178. Rownanie [] rozn = new Rownanie[2];
  179. switch (opcja) {
  180. case 0:
  181. dUc = new RozniczkaUcStO();
  182. dIl = new RozniczkaUlStO();
  183. break;
  184. case 1:
  185. dUc = new RozniczkaUcZmO();
  186. dIl = new RozniczkaUlZmO();
  187. break;
  188. case 2:
  189. dUc = new RozniczkaUcStZ();
  190. dIl = new RozniczkaUlStZ();
  191. break;
  192. case 3:
  193. dUc = new RozniczkaUcZmZ();
  194. dIl = new RozniczkaUlZmZ();
  195. break;
  196. }
  197. rozn[0] = dUc;
  198. rozn[1] = dIl;
  199.  
  200. int step =4; // RK4
  201. double h = (xk - xp) / n;
  202. //XYSeries[][] y = new XYSeries[rozn.length][n]; // wektor rozwiązań
  203. double[][] y = new double[rozn.length+1][n]; // wektor rozwiązań
  204. 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
  205. double[] k = new double[step]; // k
  206.  
  207. double x = xp; //wartosc poczatkowa dla zmiennych stanu
  208. //for (int i = 0; i < rozn.length; i++) {
  209. y[0][0] = xp;
  210. y[1][0] = uc0;
  211. y[2][0] = il0;
  212.  
  213. //}
  214.  
  215. for (int i = 1; i < n; i++) {
  216. y[0][i] = i*h+xp;
  217. for(int j=1; j<rozn.length; j++)
  218. {
  219. k[0] = h*rozn[j].rozniczka(y[0][i-1], y[1][i-1], y[2][i-1]);
  220. 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]);
  221. 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] );
  222. k[3] = h*rozn[j].rozniczka(y[0][i-1]+h, y[1][i-1]+k[2],y[2][i-1]+k[2] );
  223. y[j][i] = y[j][i-1];
  224. for (int z = 0; z < step; z++) {
  225. y[j][i] += w[z]*k[z];
  226. }
  227. }
  228. }
  229.  
  230.  
  231. return y ;
  232. }
  233.  
  234. }
Add Comment
Please, Sign In to add comment