Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package prs5;
  7.  
  8. /**
  9. *
  10. * @author Student
  11. */
  12. class PMIN extends Thread{
  13. static double f(double x, double y)
  14. {
  15. return 10*Math.sin(x)+1/Math.exp(y)+x*y;
  16. }
  17. static int lx, ly;
  18. static double ax,bx,ay,by;
  19. static double minf;
  20. double minlok;
  21. int nx,ny;
  22. public PMIN (int nx, int ny, double le100)
  23. {
  24. this.nx=nx;
  25. this.ny=ny;
  26. this.minlok=le100;
  27. this.setName("W"+nx+"X"+ny+"Y");
  28. }
  29. public static void init(int lxn, int lyn, double axn, double bxn, double ayn, double byn, double le100)
  30. {
  31. lx=lxn; ly=lyn;
  32. ax=axn; bx=bxn;
  33. ay=ayn; by=byn;
  34. minf=le100;
  35. }
  36. public void run()
  37. {
  38. double x,y;
  39. double hx=(bx-ax)/lx;
  40. double hy=(by-ay)/ly;
  41. for(int i=0; i<lx; i++)
  42. for(int j=0; j<ly; j++)
  43. {
  44. x=ax+i*hx;
  45. y=ay+j*hy;
  46. for(int k=0; k<100; k++)
  47. {
  48. x+=Math.random()*hx;
  49. y+=Math.random()*hy;
  50. if(f(x,y)<minlok)minlok=f(x,y);
  51.  
  52. }
  53. }
  54. if(minlok<minf)minf=minlok;
  55. }
  56. }
  57. public class PRS5 {
  58.  
  59. /**
  60. * @param args the command line arguments
  61. */
  62. public static void main(String[] args) {
  63. double ax=0, ay=0, bx=10, by=5;
  64. int lwx=4, lwy=2;
  65. PMIN.init(lwx, lwy, ax, bx, ay, by);
  66.  
  67. // TODO code application logic here
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement