Advertisement
szymcio93

townini4

Oct 28th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. PIERWSZE:
  2. LAGRANGE:
  3. godzina = [5,6,8,11]
  4. temp = [ -2,3,7,10]
  5.  
  6. y = [5:0.1:11]
  7.  
  8. for g = 1:61
  9. A = ones (1,4)
  10. B = ones (1,4)
  11. for i = 1:4
  12. for k = 1:4
  13. if (i~=k)
  14. A(i)=A(i)*(y(g)-godzina(k))
  15. B(i)=B(i)*(godzina(i)-godzina(k))
  16. end
  17. end
  18. L(i,g)=A(i)/B(i)
  19. end
  20.  
  21. end
  22.  
  23. T=zeros(1,61)
  24.  
  25. for g = 1 : 61
  26. for i = 1 : 4
  27. T(g)=T(g)+temp(i)*L(i,g)
  28. end
  29. end
  30.  
  31. .....................................
  32. NEWTON:
  33. godzina = [5,6,8,11]
  34. temp = [ -2,3,7,10]
  35. god = [5:0.1:11]
  36.  
  37. N=4
  38. d(:,1)=temp';
  39. for j=2:N
  40. for i=j:N
  41. d(i,j)= ( d(i-1,j-1)-d(i,j-1)) / (godzina(i-j+1)-godzina(i));
  42. end
  43. end
  44. a = diag(d)';
  45.  
  46. A2 = ones (1,61)
  47. for i=1:61
  48. for k= 1 :4
  49. A2(i)=A2(i)*(god(i)-godzina(k))
  50. end
  51. end
  52.  
  53. for g= 1:61
  54. T2(g)=-2+(5*(god(g)-5))-((god(g)-5)*(god(g)-6))+((4/30)*(god(g)-5)*(god(g)-6)*(god(g)-8))
  55. end
  56.  
  57.  
  58. hold all
  59. plot(god,T2)
  60. plot(god,T)
  61. plot(godzina,temp,'*')
  62. ..............................................................................
  63. DRUGIE:
  64. x=(-5:0.01:5);
  65. y=1./(1+x.^2);
  66. xk=-5:1:5;
  67. yk=1./(1+xk.^2);
  68. yi= interp1(xk,yk,x,'linear')
  69.  
  70.  
  71.  
  72. xk = xk';
  73. yk = 1./(1+xk.^2);
  74. cs = spline( xk', [0 yk' 0] );
  75. y3 = ppval( cs, x );
  76. plot(x,y,xk,yk,'o',x,yi,'r--',x,y3);
  77.  
  78. ....................................................................
  79. TRZECIE:
  80. clear all
  81. f1=50;
  82. f2=150;
  83. f3=10000;
  84. for n=0:9999
  85. x(n+1)=sin((2*pi*f1*n)/f3)+0.5*sin((2*pi*f2*n)/f3);
  86. end
  87. R=5;
  88. N=10000;
  89. xr=zeros(1,N);
  90. for n=0:R:N-1
  91. xr(n+1)=x(n+1);
  92. end
  93. M=1000;
  94. for m=-M:1:M
  95. h(m+M+1)=(sin((pi*m)/R))/((pi*m)/R);
  96. end
  97. h(M+1)=1;
  98.  
  99. xe=conv(xr,h);
  100.  
  101. for n=2*M+1:12000-2*M
  102. xem(n-2*M)=xe(n);
  103. end
  104. for n=M+1:N-M
  105. xm(n-M)=x(n);
  106. end
  107.  
  108. ........................................
  109. function [ ] = lab4_3( R, M )
  110. %UNTITLED Summary of this function goes here
  111. % Detailed explanation goes here
  112. f
  113. 1 = 50;
  114.  
  115. f2 = 150;
  116.  
  117. fs = 10000;
  118.  
  119. for n = 0:9999;
  120.  
  121. x(n+1) = sin(2*pi()*f1 * n / fs) + 0.5*sin(2*pi()*f2*n/fs);
  122.  
  123. end
  124.  
  125. plot(x)
  126.  
  127. hold on
  128.  
  129. input('')
  130.  
  131. xr(10000)=0;
  132.  
  133. for n=0:R:9999
  134.  
  135. xr(n+1) = x(n+1);
  136.  
  137. end
  138.  
  139. plot(xr, 'g')
  140.  
  141. hold off
  142.  
  143. input('')
  144.  
  145. h(M+1)=1;
  146.  
  147. for m=1:M
  148.  
  149. h(m) = sinc(pi()*(M+1-m)/R);
  150.  
  151. h(m+M+1) = sinc(pi()*m/R);
  152.  
  153. end
  154.  
  155. plot(h)
  156.  
  157. input('')
  158.  
  159. xe=conv(xr, h);
  160.  
  161. xe2 = xe(2*M:length(xe)-2*M);
  162.  
  163. x2 = x(M:length(x)-M);
  164.  
  165. plot(xe2-x2, '-')
  166.  
  167. input('')
  168.  
  169. %plot(x2)
  170.  
  171. %hold on;
  172.  
  173. %plot(xe2, '-g');
  174.  
  175. % length(x2)
  176.  
  177. % length(xe2)
  178.  
  179. %plot(abs(abs(xe2) - abs(x2)), '.');
  180.  
  181. %plot(h);
  182.  
  183. %plot(xd)
  184.  
  185. end
  186.  
  187.  
  188. ..............................
  189. fp=10000;
  190. f1=50;
  191. f2=150;
  192.  
  193. for i = 1:10000
  194. iks(i)=sin((2*pi*f1*i)/fp)+1/2*sin((2*pi*f2*i)/fp);
  195. end
  196.  
  197. R1=5;
  198. R2=10;
  199. R3=25;
  200. iks1=iks;
  201. iks2=iks;
  202. iks3=iks;
  203.  
  204. for i = 1:10000
  205. if (rem(i,R1)~=0)
  206. iks1(i)=0;
  207. end
  208. end
  209. for i = 1:10000
  210. if (rem(i,R2)~=0)
  211. iks2(i)=0;
  212. end
  213. end
  214. for i = 1:10000
  215. if (rem(i,R3)~=0)
  216. iks3(i)=0;
  217. end
  218. end
  219.  
  220. M=1000;
  221. for m=-M:M
  222. h1(m+M+1)=(sin((pi*m)/R1))/((pi*m)/R1);
  223. end
  224. h1(M+1)=1;
  225.  
  226. for m=-M:M
  227. h2(m+M+1)=(sin((pi*m)/R2))/((pi*m)/R2);
  228. end
  229. h2(M+1)=1;
  230.  
  231. for m=-M:M
  232. h3(m+M+1)=(sin((pi*m)/R3))/((pi*m)/R3);
  233. end
  234. h3(M+1)=1;
  235.  
  236. splot1 = conv(iks1,h1);
  237. splot2 = conv(iks2,h2);
  238. splot3 = conv(iks3,h3);
  239.  
  240. splot1 = splot1(2*M:end-2*M);
  241. splot2 = splot2(2*M:end-2*M);
  242. splot3 = splot3(2*M:end-2*M);
  243.  
  244. iks=iks(M:end-M);
  245. iks1=iks1(M:end-M);
  246. iks2=iks2(M:end-M);
  247. iks3=iks3(M:end-M);
  248.  
  249.  
  250. subplot(3,1,1); plot(iks)
  251. subplot(3,1,2); plot(iks3)
  252. subplot(3,1,3); plot(splot3)
  253.  
  254.  
  255. zaba=zeros(1,N);
  256.  
  257. for i=0:N-1
  258. for k =0:(N/R1-1)
  259. zaba(i+1)=zaba(i+1)+iks(k*R1+1)*(sinc((i-k*R1)/R1));
  260. end
  261. end
  262.  
  263.  
  264. ....................................................................................
  265. function f = newton(x, y, p)
  266.  
  267. n = length(x);
  268. d(:,1)=y';
  269. for j=2:n
  270. for i=j:n
  271. d(i,j)= ( d(i-1,j-1)-d(i,j-1)) / (x(i-j+1)-x(i));
  272. end
  273. end
  274. a = diag(d)';
  275.  
  276. Df(1,:) = ones(size(p));
  277. c(1,:) = a(1)*ones(size(p));
  278. for j = 2 : n
  279. Df(j,:)=(p - x(j-1)) .* Df(j-1,:);
  280. c(j,:) = a(j) .* Df(j,:);
  281. end
  282. f=sum(c);
  283. ....................................................................................
  284. function y=Lk(x,xk,k)
  285.  
  286. n=length(x)-1;
  287. ni=length(k);
  288. L=ones(n+1,ni);
  289. for i=0:n
  290. for j=0:(i-1)
  291. L(j+1,:)=L(j+1,:).*(k-x(i+1))/(x(j+1)-x(i+1));
  292. end
  293.  
  294. for j=i+1:n
  295. L(j+1,:)=L(j+1,:).*(k - x(i+1))/(x(j+1)-x(i+1));
  296. end
  297. end
  298. y = xk * L;
  299. ....................................................................................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement