SHARE
TWEET

13.1

a guest Apr 19th, 2019 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Апроксимация функции 13-1
  2. clc
  3. clf
  4. funcprot(0)                                                                  
  5. disp('Задание 1')
  6. x=[-2:0.3:6];
  7. y=x+cos(x-2);
  8. z=[x;y];
  9. plot(x,y,'r*'),xgrid();
  10. xi=-3:0.3:7;
  11. a=gca();
  12. a.x_location = "origin";
  13. a.y_location = "origin";                                          
  14. xname('Задание 1:  Апроксимация функции')
  15.  
  16. disp('Полином 1 степени:')
  17. function zr=p(c,z)
  18.     zr=z(2)-c(1)-c(2)*z(1)
  19. endfunction
  20.  
  21. sleep(1200)
  22. c=[0;0];
  23. [a,S]=datafit(p,z,c)
  24. disp(S,'S1=')
  25. disp(a,'a1=')
  26. p=poly([a],'x','c');
  27. disp(p,'Q1(x)=')
  28.  
  29.  
  30. pxi=a(1)+a(2)*xi
  31. plot(xi,pxi,'m'), xgrid()
  32.  
  33. disp('Полином 2 степени:')
  34. sleep(1200)
  35. function zr=p(c,z)
  36.     zr=z(2)-c(1)-c(2)*z(1)-c(3)*z(1).^2
  37. endfunction
  38.  
  39. c=[0;0;0];
  40. [a,S]=datafit(p,z,c)
  41. disp(S,'S2=')
  42. disp(a,'a2=')
  43. p=poly([a],'x','c');
  44. disp(p,'Q2(x)=')
  45.  
  46. pxi=a(1)+a(2)*xi+a(3)*xi.^2
  47. plot(xi,pxi,'g'), xgrid()
  48.  
  49. disp('Полином 3 степени:')
  50. sleep(1200)
  51. function zr=p(c,z)
  52.     zr=z(2)-c(1)-c(2)*z(1)-c(3)*z(1).^2-c(4)*z(1).^3
  53. endfunction
  54.  
  55. c=[0;0;0;0];
  56. [a,S]=datafit(p,z,c)
  57. disp(S,'S3=')//погрешность
  58. disp(a,'a3=')//коэффициенты
  59. p=poly([a],'x','c');
  60. disp(p,'Q3(x)=')                                                                  
  61.  
  62. pxi=a(1)+a(2)*xi+a(3)*xi.^2+a(4)*xi.^3
  63. plot(xi,pxi,axesflag=5),legend('x+cos(x-2)','n=1','n=2','n=3',4)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top