Advertisement
szymcio93

townini101010101010

Dec 16th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. PIERWSZEEE
  2.  
  3. clear all;
  4. close all;
  5. V=0.33;
  6. C1 = 1;
  7. C2 = 2*C1;
  8. i=0;
  9. max = 2;
  10. for r=0:0.1:max
  11. i=i+1;
  12. r
  13. P(i) = (C1*2*pi*r*r*r + 2*V*C2)/r;
  14. end
  15. hold on;
  16. plot(0:0.1:max, P, 'r');
  17. C2 = C1;
  18. i=0;
  19. for r=0:0.1:max
  20. i=i+1;
  21. P2(i) = (C1*2*pi*r*r*r + 2*V*C2)/r;
  22. end
  23. plot(0:0.1:max, P2, 'g');
  24.  
  25. a=0;
  26. b=1;
  27. k = (sqrt(5)-1)/2;
  28. xL = b-k*(b-a);
  29. xR = a+k*(b-a);
  30. while (b-a)>1e-6
  31. if f(xL)<f(xR)
  32. b = xR;
  33. xR = xL;
  34. xL = b-k*(b-a);
  35. else
  36. a = xL;
  37. xL = xR;
  38. xR = a+k*(b-a);
  39. end
  40. end
  41. xopt = (a+b)/2;
  42. wymiary=[xopt,0.33*(1/(pi*xopt^2))]
  43.  
  44. a=0;
  45. b=1;
  46. k = (sqrt(5)-1)/2;
  47. xL = b-k*(b-a);
  48. xR = a+k*(b-a);
  49. while (b-a)>1e-6
  50. if f1(xL)<f1(xR)
  51. b = xR;
  52. xR = xL;
  53. xL = b-k*(b-a);
  54. else
  55. a = xL;
  56. xL = xR;
  57. xR = a+k*(b-a);
  58. end
  59. end
  60. xopt = (a+b)/2;
  61. wymiary=[xopt,0.33*(1/(pi*xopt^2))]
  62.  
  63. .....................
  64. f1
  65. function [ f ] = f( x )
  66.  
  67. f=0.66*(1/x)+4*pi*x^2;
  68.  
  69. end
  70.  
  71. f
  72. function [ f ] = f( x )
  73.  
  74. f=0.66*(1/x)+2*pi*x^2;
  75.  
  76. end
  77.  
  78.  
  79. ------------------------------------------------------------------------
  80. TRZECIE333333333333
  81.  
  82. close all;
  83. clear all;
  84. x = fun(0,0);
  85. for i=-100:100
  86. for j=-100:100
  87. if fun(i,j)<x(1)
  88. x(1) = fun(i,j);
  89. x(2) = i;
  90. x(3) = j;
  91. end
  92. end
  93. end
  94. x
  95.  
  96. ----------------------------------------------------------------------------
  97. 222222222222222:
  98.  
  99. clear all;
  100. close all;
  101. optimset('MaxFunEvals', 1e15);
  102. load lab10_2.mat;
  103. in = in_all(:,3);
  104. initial_f = 1;0.001;
  105. initial_A = 1;
  106. initial_a = 1;
  107. % estymacja parametrów
  108. fs = 0;
  109. Nx = length(in);
  110. initParm = [ initial_f, initial_A, initial_a ]; % parametry początkowe
  111. outParm = fminsearch( @(x) fitSinDamp(x, in, fs, Nx) , initParm );
  112. estimated_f = outParm(1);
  113. estimated_A = outParm(2);
  114. estimated_a = outParm(3);
  115. x=0:10/999:10;
  116. y1 = exp(-estimated_a*x)*estimated_A.*sin(2*pi*estimated_f*x);
  117. %plot(0:10/999:10, y1);
  118. %plot(0:10/999:10, in, 'r');
  119. %hold on
  120. max(std(y1'-in))
  121. %plot(in, 'r');
  122. % porównanie przebiegu wygenerowanego z odtworzonym
  123. % ToDo
  124.  
  125. ----------
  126.  
  127. function y = fitSinDamp( parm, x, fs, Nx )
  128. % x – docolowy sygnał
  129. % fs – częstotliwość prókowania
  130. % Nx – długość sygnału
  131. f = parm(1); % częstotliwość sinusoidy
  132. A = parm(2); % początkowa amplituda
  133. a = parm(3); % szybkość opadania
  134. z=0:10/999:10;
  135. y = exp(-a*z)*A.*sin(2*pi*f*z);
  136. y=std(y'-x);
  137. % ToDo – mniejsza wartość == lepsze dopasowanie
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement