Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 2.00 KB | None | 0 0
  1. //Zadanie 1, grupa A - METODA EULERA
  2.  
  3. clear
  4.  
  5. figure
  6.  
  7. function f=funkcja(x,y)
  8.     f=2*y+8*x
  9. endfunction
  10.  
  11. h=0.01
  12. x=1.5:h:3.5
  13. y(1)=2
  14.  
  15. for i=1:2/h
  16.     y(i+1)=y(i)+h*funkcja(x(i),y(i))
  17. end
  18.  
  19. plot(x,y,'m')
  20.  
  21. legend('METODA EULERA - h=0.01',4)
  22. xgrid
  23.  
  24. //Zadanie 1, grupa B - METODA ZMODYFIKOWANA EULERA
  25.  
  26. figure
  27.  
  28. clear
  29.  
  30. function f=funkcja(x,y)
  31.     f=3*x^2-y
  32. endfunction
  33.  
  34. h=0.01
  35. x=0:h:5
  36. y(1)=0
  37.  
  38. for i=1:5/h
  39.     y0=y(i)+h*funkcja(x(i),y(i))
  40.     y(i+1)=y(i)+h*(funkcja(x(i),y(i))+funkcja(x(i+1),y0))/2
  41. end
  42.  
  43. plot(x,y,'b')
  44.  
  45. legend('METODA ZMODYFIKOWANA EULERA',4)
  46. xgrid
  47.  
  48. //Zadanie 1, grupa TOB - METODA RALSONA
  49.  
  50. figure
  51.  
  52. clear
  53.  
  54. function f=funkcja(x,y)
  55.     f=6*x^2+6
  56. endfunction
  57.  
  58. h=0.01
  59. y(1)=7
  60. x=2:h:12
  61.  
  62. for i=1:10/h
  63.     k1=funkcja(x(i),y(i))
  64.     k2=funkcja(x(i)+0.75*h,y(i)+0.75*k1*h)
  65.     y(i+1)=y(i)+(1/3*k1+2/3*k2)*h
  66. end
  67.  
  68. plot(x,y,'y')
  69. xgrid
  70.  
  71. legend('METODA RALSONA')
  72.  
  73.  
  74. //Zadanie 2, grupa A - METODA OBSZARÓW KOLOKACJI
  75.  
  76. clear
  77.  
  78. figure
  79.  
  80. n11=integrate ('1-x' , 'x' , 0, 1/3)
  81. n12=integrate ('2*x-x^2' , 'x' , 0 ,1/3)
  82. n13=integrate ('-x^3+3*x^2' , 'x' , 0 ,1/3)
  83.  
  84. n21=integrate ('1-x' , 'x' , 1/3, 2/3)
  85. n22=integrate ('2*x-x^2' , 'x' , 1/3, 2/3)
  86. n23=integrate ('-x^3+3*x^2' , 'x' , 1/3, 2/3)
  87.  
  88. n31=integrate ('1-x' , 'x' , 2/3, 1)
  89. n32=integrate ('2*x-x^2' , 'x' , 2/3, 1)
  90. n33=integrate ('-x^3+3*x^2' , 'x' , 2/3, 1)
  91.  
  92.  
  93. q1=integrate ('x-1.5' , 'x' , 0 , 1/3)
  94. q2=integrate ('x-1.5' , 'x' , 1/3 , 2/3)
  95. q3=integrate ('x-1.5' , 'x' , 2/3 , 1)
  96.  
  97. A3=[n11 , n12, n13 ; n21 , n22 , n23 ; n31 , n32 , n33]
  98. b3=[q1;q2;q3]
  99. t3=linsolve (A3,b3)
  100.  
  101. x=0:0.1:1
  102.     y3=1.5+t3(1,1)*x+t3(2,1)*x^2+t3(3,1)*x^3
  103. plot (x,y3,'.-g')
  104.  
  105. legend('METODA OBSZARÓW KOLOKACJI',4)
  106. xgrid
  107.  
  108.  
  109. //Zadanie 2, TOB - METODA PUNKTÓW KOLOKACJI
  110.  
  111. figure
  112.  
  113. clear
  114.  
  115. x=3:0.01:4
  116. k1=10/3
  117. k2=11/3
  118.  
  119. A2=[13.407 , 136.222;16.148 , 112.889]
  120. b2=[-23.333;-26.666]
  121. t2=linsolve (A2,b2)
  122.  
  123. x=3:0.01:4
  124. y2=x+t2(1,1).*(x-3).*(x-4).*x+t2(2,1)*(x-3).*(x-4)
  125.  
  126. plot (x,y2, 'm')
  127.  
  128.  
  129. legend('METODA PUNKTÓW KOLOKACJI',4)
  130. xgrid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement