Advertisement
Guest User

wykres z podziałem

a guest
Jan 21st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.81 KB | None | 0 0
  1. %plik nazwać fun
  2. function y=fun(x, T, y1, y2, y3, y4)
  3.  
  4.  
  5. r = rem(x,T)/T;
  6. if (r < 1/4)
  7.     y=y1(x);
  8. elseif (r <1/2)
  9.     y=y2(x);
  10. elseif (r <3/4)
  11.     y=y3(x);
  12. else
  13.     y=y4(x);
  14. end
  15. end
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. ----------
  24. %zad.3
  25. clc; clear; close all;
  26.  
  27. x=0:0.01:10;
  28. T=ones(1,length(x)).*10;
  29.  
  30. y1=@(x) cos(x);
  31. y2=@(x) sin(x);
  32. y3=@(x) x.^(0.12);
  33. y4=@(x) 2*x;
  34.  
  35. %figure(1)
  36. %    subplot(4,1,1); plot(x, arrayfun(@fun, x, T, y1, y2, y3, y4));
  37. %    %subplot(4,1,2); plot(x,y,'r-');
  38.    
  39.  
  40. y=[];
  41. for i=1:length(x)
  42.     y=[y, fun(x(i), T, y1, y2, y3, y4)];
  43. end
  44.  
  45. figure(1)
  46.     subplot(3,1,1); plot(x,y,'r-');
  47.     subplot(6,1,3); plot(x,arrayfun(y1, x),'r-');
  48.     subplot(6,1,4); plot(x,arrayfun(y2, x),'r-');
  49.     subplot(6,1,5); plot(x,arrayfun(y3, x),'r-');
  50.     subplot(6,1,6); plot(x,arrayfun(y4, x),'r-');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement