Advertisement
HODIDIIL

PMN KOLOS

Apr 20th, 2022
1,606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 3.74 KB | None | 0 0
  1. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1.INTERPOLACJA LANGREGA
  2. clc
  3. clear
  4. xdel
  5.  
  6. n=4
  7. X=[-2;-1.5;3;5]
  8. Y=[7;11;16;-1]
  9. a = zeros(n)
  10. for i = 1:n
  11. il=1
  12. for j = 1:n
  13. if i <> j
  14. il=il*(X(i)-X(j))
  15. end
  16. end
  17. a(i) = Y(i)/il
  18. end
  19. disp('a')
  20. disp(a)
  21. function [w] = W(z)
  22. fun = 0
  23. for i = 1:n
  24. il=1
  25. for j = 1:n
  26. if i <> j
  27. il = (z - X(j)).* il
  28. end
  29. end
  30. fun = fun + a(i)*il
  31. end
  32. w = fun
  33. endfunction
  34. disp('W(-0.5)')
  35. disp(W(-0.5))
  36. z = -3:0.1:6
  37. plot(X,Y,'redx')
  38. plot(z,W(z))
  39. plot(-0.5,W(-0.5),'greeno')
  40.  
  41. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!112.INTERPOLACJA WIELOMIANOWA
  42. clc
  43. clear
  44. xdel
  45.  
  46. n=5
  47. x=[-3;-2;-0.5;1;3.5]
  48. y=[4;4.8;-1.2;7;13]
  49. X=zeros(5,5)
  50. m = size(X,"r")
  51. n = size(X,"c")
  52. for i=1:n
  53.     for j=1:n
  54.         X(i,j)=x(i)^(j-1)
  55.     end
  56.     end
  57.     disp(X)
  58. a=inv(X)*y
  59. disp('wektor a:')
  60. for i=1:n
  61.     disp(a(i))
  62. end
  63. function [w]=W(z)
  64.     w=a(1)+a(2)*z+a(3)*z^2+a(4)*z^3+a(5)*z^4
  65. endfunction
  66. disp('wartosc dla 0.5:')
  67. Res1=W(0.5)
  68. disp(Res1)
  69. s=-4:0.1:4
  70. plot(s,W(s))
  71. plot(x,y, 'redx')
  72.  
  73. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1111113.NEWTON I WZOR
  74. clc
  75. clear
  76. xdel
  77.  
  78. disp('I wzor Newtona:')
  79.  
  80. n=6
  81.  
  82. x=[0.8;1;1.2;1.4;1.6;1.8]
  83. y=[-3.52;-5;-6.72;-8.68;-10.88;-13.32]
  84. for i=1:n
  85.  
  86.     z(i,1)=x(i,1)
  87.     z(i,2)=y(i,1)
  88. end
  89. disp(z)
  90.  
  91. disp('tabela roznic:')
  92. for j=3:n+1
  93.     for i=1:n-j+2
  94.         z(i,j)=z(i+1,j-1)-z(i,j-1)
  95. end
  96. end
  97. disp(z)
  98. h=0.2
  99. s=1.3
  100. //k=z(3,1)
  101. k=3
  102.  
  103. q=((1.3-z(k,1))/h)
  104.  
  105. disp('q:')
  106.  
  107. disp(q)
  108. function [w]=f(s)
  109. q=(s-x(k))/h
  110. w = z(k,2)+(z(k,3).*q)+(z(k,4).*(q.*(q-1))/2)+(z(k,5).*(q.*(q-1).*(q-2))/6)
  111. endfunction
  112. disp("W(s)=")
  113. disp(f(s))
  114. s=0.6:0.1:2
  115. plot(x,y,'redx')
  116. plot(s,f(s))
  117.  
  118. !!!!!!!!!!!!!!!!!!!!!!!!!!11!!!!!!!!!!!!!!!!!!!!!!!!4.NEWTON II WZOR
  119. clc
  120. clear
  121. xdel
  122.  
  123. disp("2 wzor newtona:")
  124. n=4
  125.  
  126. x=[50;100;150;200]
  127. y=[-6.912;-7.605;-8.011;-8.298]
  128. for i=1:n
  129.  
  130.     z(i,1)=x(i,1)
  131.     z(i,2)=y(i,1)
  132. end
  133. disp(z)
  134. disp('tabela roznic:')
  135. for j=3:n+1
  136.     for i=1:n-j+2
  137.         z(i,j)=z(i+1,j-1)-z(i,j-1)
  138. end
  139. end
  140. disp(z)
  141. h=50
  142. s=175
  143. //k=z(3,1)
  144. k=3
  145.  
  146. q=((1.3-z(k,1))/h)
  147.  
  148. disp('q:')
  149.  
  150. disp(q)
  151. function [w]=f(s)
  152. q=(s-x(k))/h
  153. w = z(k,2)+(z(k-1,3).*q)+(z(k-2,4).*(q.*(q-1))/2)
  154. endfunction
  155. disp("W(s)=")
  156. disp(f(s))
  157. s=50:0.1:250
  158. plot(x,y,'redx')
  159. plot(s,f(s))
  160.  
  161. !!!!!!!!!!!!!!1!!!!!!!!!!!!!!!!!!!!!!!!!!!15.GAUSS
  162. clc
  163. clear
  164. xdel
  165.  
  166. a=2
  167. b=8
  168. z=0
  169. calka=0
  170. n=4
  171. ksi=[-0.86113;-0.339098;0.33998;0.86113]
  172. w=[0.34785;0.65214;0.65214;0.34785]
  173.  
  174. function W1=f(z)
  175. W1=3.5*z^(1/2)
  176. endfunction
  177.  
  178. function W2 = F(ksi)
  179. z =((b+a)/2)+((b-a)/2)*ksi
  180. W2 =((b-a)/2)*f(z)
  181. endfunction
  182. for i =1:(n)
  183.  
  184. calka = calka + F(ksi(i))*w(i)
  185. end
  186. disp(calka)
  187. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!6.PROSTOKATY
  188. clc
  189. clear
  190. xdel
  191.  
  192. a = 2;
  193. b = 8;
  194. n = 1000;
  195. calka_pr = 0;
  196. function W = f(z)
  197. W = 3.5*z^(1/2)
  198. endfunction
  199.  
  200. h = (b-a)/n
  201.  
  202. for i =1:(n)
  203. x(i) = a + ((i-1) * h)
  204.  
  205. calka_pr = calka_pr + (h * f(x(i)))
  206. end
  207.  
  208. disp(calka_pr);
  209. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!7.TRAPEZY
  210. clc
  211. clear
  212. xdel
  213.  
  214. a = 2;
  215. b = 8;
  216. n = 1000;
  217. calka_tr = 0;
  218. wynik = 0;
  219. x = zeros(n,1)
  220. y = zeros(n,1)
  221.  
  222. function W = f(z)
  223. W = 3.5*z^(1/2)
  224. endfunction
  225.  
  226. h = (b-a)/n
  227.  
  228. for i =2:(n)
  229. x(i+1) = a + ((i-1)*h)
  230. y(i+1) = f(x(i+1))
  231. if(i>0)
  232. wynik = wynik + y(i+1)
  233. end
  234. end
  235.  
  236. calka_tr = h*(((y(1)+y(n))/2) + wynik)
  237.  
  238. disp(calka_tr)
  239. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!8.KUBATURA GAUSSA
  240. clc
  241. clear
  242. xdel
  243.  
  244. n=3
  245. i=0
  246. calka=0
  247. J=0
  248. n=3
  249. x=[1;3;1]
  250. y=[1;3;3]
  251. ksi=[0.5;0;0.5]
  252. eta=[0.5;0.5;0]
  253. wi=[1/3;1/3;1/3]
  254. function wynik=f(x,y)
  255.    wynik=3*log(x)*(y^2+7)
  256. endfunction
  257. J=((x(2)-x(1))*(y(3)-y(1)))-((x(3)-x(1))*(y(2)-y(1)))
  258. disp(J)
  259. function wynik1=F(ksi,eta)
  260.     wynik1=abs(J)*f(x(1)+(x(2)-x(1))*ksi+(x(3)-x(1))*eta,y(1)+(y(2)-y(1))*ksi+(y(3)-y(1))*eta)
  261.       endfunction
  262. for i=1:n
  263.     calka=calka+(F(ksi(i),eta(i))*wi(i))
  264. end
  265. disp(0.5*calka)
  266.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement