Advertisement
FancyDevs

Matlab Examples

Jan 22nd, 2020
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.24 KB | None | 0 0
  1. %Macierz m na n z jedynkami i ciąg fibbanaciego
  2.  
  3. function[A] = f2(m,n)
  4. A = ones(m,n);
  5. for i = 3:m*n
  6.     A(i) = A(i-1)+A(i-2);
  7. end
  8. end
  9.  
  10. %Jeżeli x to
  11.  
  12. function zad2(x)
  13. if x<0
  14.     x=x^2-5
  15. elseif x==0
  16.     x=0
  17. elseif x>0
  18.     x=-x^3+7
  19. end
  20.  
  21. %Rysuje funkcję dla powyższego x
  22.  
  23. x1=[-20,0];
  24. x2=0;
  25. x3=[0,10];
  26.  
  27. plot(x1,x1.^2-5,x2,0,x3,x3.^3+7);
  28.  
  29. %kolorowanie obrazu
  30.  
  31. A=imread('obraz.jpg');
  32. A(1:end,1:20,2)=0;
  33. A(1:end,1:20,3)=0;
  34. A(1:20,21:end,2)=0;
  35. A(1:20,21:end,3)=0;
  36. A(21:end,370:end,2)=0;
  37. A(21:end,370:end,3)=0;
  38. A(370:end,21:369,2)=0
  39. A(370:end,21:129,3)=0;
  40. image(A)
  41.  
  42. %negatyw obrazu
  43.  
  44. A = imread('obraz.jpg');
  45.  
  46. B = 255-A;
  47. C = A(30:end-30,30:end-30,:);
  48. B(30:end-30,30:end-30,:) = C;
  49.  
  50. image(B);
  51.  
  52. %Zad 4 rysowanie wykresow
  53.  
  54. Um=325
  55. t=[0:0.001:50]
  56. w1=2*pi*50;
  57. U1=Um*sin(w1*t/1000);
  58. U2=Um*sin(2*pi/3+w1*t/1000);
  59. U3=Um*sin(4*pi/3+w1*t/1000);
  60. w31=2*pi*50*3
  61. w32=2*pi*50*5
  62. w33=2*pi*50*7
  63. U31=Um*sin(w31*t/1000);
  64. U32=Um*sin(2*pi/3+w32*t/1000);
  65. U33=Um*sin(4*pi/3+w33*t/1000);
  66. U41=U1+U31;
  67. U42=U2+U32;
  68. U43=U3+U31;
  69. Um1=U1-U2;
  70. Um2=U2-U3;
  71. Um3=U3-U1;
  72.  
  73. ax1=subplot(4,1,1);
  74. ax2=subplot(4,1,2);
  75. ax3=subplot(4,1,3);
  76. ax4=subplot(4,1,4);
  77. plot(ax1,t,U1,'b-',t,U2,'k-',t,U3,'r-');
  78.  
  79. plot(ax2,t,Um1,t,Um2,t,Um3);
  80.  
  81. plot(ax3,t,U31,t,U32,t,U33);
  82. plot(ax4,t,U41,t,U42,t,U43);
  83.  
  84. %Rysowanie wykresów dokumentacja
  85.  
  86. % Create data and 2-by-1 tiled chart layout
  87. x = linspace(0,3);
  88. y1 = sin(5*x);
  89. y2 = sin(15*x);
  90. tiledlayout(2,1)
  91.  
  92. % Top plot
  93. ax1 = nexttile;
  94. plot(ax1,x,y1)
  95. title(ax1,'Top Plot')
  96. ylabel(ax1,'sin(5x)')
  97.  
  98. % Bottom plot
  99. ax2 = nexttile;
  100. plot(ax2,x,y2)
  101. title(ax2,'Bottom Plot')
  102. ylabel(ax2,'sin(15x)')
  103.  
  104. %zad5
  105.  
  106. ******Funkcja******
  107. function[y] = f1(f,x)
  108.  
  109. y = 0;
  110.  
  111. for i = 2:length(x)
  112.     y = y + ( (f(i)+f(i-1))*(x(i)-x(i-1)))/2;
  113. end
  114.  
  115.  
  116. end
  117.  
  118. ******Skrypt********
  119. x1 = [0:0.0001:10];
  120. x2 = [0:0.0001:2*pi];
  121. y1 = 3*x1+10;
  122. y2 = sin(x2);
  123. y3 = x1.^2-3*x1+1;
  124.  
  125. a = f1(y1,x1);
  126. b = f1(y2,x2);
  127. c = f1(y3,x1);
  128. a
  129. b
  130. c
  131.  
  132. %zad5 inne
  133.  
  134. syms x
  135. y=3*x^4+x^3+7*x^2+4
  136. dx=diff(y)
  137. dxx=diff(dx)
  138. i=int(y)
  139. fplot(y)
  140. hold on
  141. fplot(dx)
  142. fplot(dxx)
  143. fplot(i)
  144. legend("Funkcja pierwotna", "Pochodna pierwszego rzedu", "Pochodna drugiego rzedu", "Calka z y",'location','SouthEast')
  145. grid('on')
  146. grid('minor')
  147. title("Wykres zad5")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement