Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. %% Problem 5. Method of simple iteration
  2. clear all,format ,clc, format compact
  3. A=[4, 4, 3;3, 7, -1;3, -1, 35];b=[7; 19; -2];
  4. tau=0.08; x=zeros(3,1);
  5. itermax=80;
  6. ni=1; % is the coefficient matrix positive definite?
  7. for i=1:3
  8. if det(A(1:i,1:i))>0
  9. else ni=2; break
  10. end
  11. end
  12. if ni==2
  13. disp('the coefficient matrix is not positive definite'),
  14. return
  15. end
  16. check=isequal(A,A');
  17. if check==0
  18. disp('the coefficient matrix is not symmetric'),
  19. return
  20. end
  21. disp('A is symmetric and positive definite ')
  22.  
  23. disp('Answer:')
  24. disp(' k_iter=251, X_approx=[x1=1.003,x2=1.999,x3=2.999]')
  25.  
  26. %% Problem 6 interpolating polynomial
  27. clear all, clc ,close all, format compact, format
  28. xnodes=[2.1, 2.6, 3.1, 3.6, 4.1, 4.6, 5.1, 5.6];
  29. ynodes=[2.37,3.36, 3.97, 4.11, 3.84, 3.30, 2.71, 2.33];
  30. coef=ynodes; % determination of 𝒂𝟏, 𝒂𝟐, …
  31. for k = 2:8
  32. coef(k:8) = (coef(k:8) - coef(k-1:7))./(xnodes(k:8) - xnodes(1:9-k));
  33. end
  34. syms x
  35. pol= coef(7); % coefficients of the polynomial
  36. for k = 7:-1:1
  37. pol=pol*(x-xnodes(k))+coef(k);
  38. end
  39. polyn=collect(pol)
  40. coefpol=sym2poly(polyn)
  41. % coefficients of the polynomial (format double)
  42.  
  43. graph1 = ezplot(polyn,[1,8])
  44. hold on
  45. plot(xnodes,ynodes,'o','LineWidth',3)
  46. hold off
  47. set(graph1,'LineWidth',3,'Color','r','LineStyle','-')
  48. title('Newton interpolating polynomial')
  49. legend('polynomial','nodes')
  50. ylim([1 5]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement