icatalin

matlab 15.03.2018

Mar 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. %Trimitem temele cu publish, in format html. Schimbam numele folderului in nume, grupa.
  2. %ex1.m
  3. syms x
  4. f = x^4 + 2*x^2-x-3;
  5. ezplot(f,[1,2]);
  6.  
  7. fi2=sqrt((3+x-x.^4)/2);
  8. fi4=(3*x^4 + 2*x^2 + 3)/(4*x^3+4*x-1);
  9.  
  10. figure(2);
  11. subplot(1,2,1);
  12. ezplot(fi2,[1,2]);
  13. subplot(1,2,2);
  14. ezplot(fi4,[1,2]);
  15.  
  16. dfi4=diff(fi4);
  17. figure(3);
  18. ezplot(dfi4,[1,2]);
  19.  
  20. fi4=inline(fi4,'x');
  21. xaprox=MetPunctFix(fi4,1.5,20);
  22.  
  23. figure(1);
  24. hold on;
  25. plot(xaprox,subs(f,x,xaprox),'o');
  26.  
  27. $MetPunctFix.m
  28. function [xaprox]=MetPunctFix(fi,x0,n)
  29. x(1)=x0;
  30. for k = 2:n
  31. x(k)=double(fi(x(k-1)));
  32. end
  33. xaprox=x(k)
  34. end
  35.  
  36. %ex1 fara functie separata
  37. function Ex1
  38.  
  39. syms x
  40. f = x^4 + 2*x^2-x-3;
  41. ezplot(f,[1,2]);
  42.  
  43. fi2=sqrt((3+x-x.^4)/2);
  44. fi4=(3*x^4 + 2*x^2 + 3)/(4*x^3+4*x-1);
  45.  
  46. figure(2);
  47. subplot(1,2,1);
  48. ezplot(fi2,[1,2]);
  49. subplot(1,2,2);
  50. ezplot(fi4,[1,2]);
  51.  
  52. dfi4=diff(fi4);
  53. figure(3);
  54. ezplot(dfi4,[1,2]);
  55.  
  56. fi4=inline(fi4,'x');
  57. xaprox=MetPunctFix(fi4,1.5,20);
  58.  
  59. figure(1);
  60. ezplot(f,[1,2]);
  61. hold on;
  62. f=inline(f,'x');
  63. plot(xaprox,f(xaprox),'o');
  64.  
  65. function [xaprox]=MetPunctFix(fi,x0,n)
  66. x(1)=x0;
  67. for k = 2:n
  68. x(k)=double(fi(x(k-1)));
  69. end
  70. xaprox=x(k)
  71. end
  72.  
  73. end
  74.  
  75. %ex2
  76. syms x
  77. f=x^3-2*x^2-5
  78. eps=10^(-4)
  79. ezplot(f,[1,4]);
  80.  
  81. df=diff(f);
  82.  
  83. f=inline(f,'x');
  84. df=inline(df,'x');
  85.  
  86. xaprox=MetNewton(f,df,2,eps);
  87.  
  88. hold on;
  89. plot(xaprox,f(xaprox),'o')
Add Comment
Please, Sign In to add comment