Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Problem 5. Method of simple iteration
- clear all,format ,clc, format compact
- A=[4, 4, 3;3, 7, -1;3, -1, 35];b=[7; 19; -2];
- tau=0.08; x=zeros(3,1);
- itermax=80;
- ni=1; % is the coefficient matrix positive definite?
- for i=1:3
- if det(A(1:i,1:i))>0
- else ni=2; break
- end
- end
- if ni==2
- disp('the coefficient matrix is not positive definite'),
- return
- end
- check=isequal(A,A');
- if check==0
- disp('the coefficient matrix is not symmetric'),
- return
- end
- disp('A is symmetric and positive definite ')
- disp('Answer:')
- disp(' k_iter=251, X_approx=[x1=1.003,x2=1.999,x3=2.999]')
- %% Problem 6 interpolating polynomial
- clear all, clc ,close all, format compact, format
- xnodes=[2.1, 2.6, 3.1, 3.6, 4.1, 4.6, 5.1, 5.6];
- ynodes=[2.37,3.36, 3.97, 4.11, 3.84, 3.30, 2.71, 2.33];
- coef=ynodes; % determination of 𝒂𝟏, 𝒂𝟐, …
- for k = 2:8
- coef(k:8) = (coef(k:8) - coef(k-1:7))./(xnodes(k:8) - xnodes(1:9-k));
- end
- syms x
- pol= coef(7); % coefficients of the polynomial
- for k = 7:-1:1
- pol=pol*(x-xnodes(k))+coef(k);
- end
- polyn=collect(pol)
- coefpol=sym2poly(polyn)
- % coefficients of the polynomial (format double)
- graph1 = ezplot(polyn,[1,8])
- hold on
- plot(xnodes,ynodes,'o','LineWidth',3)
- hold off
- set(graph1,'LineWidth',3,'Color','r','LineStyle','-')
- title('Newton interpolating polynomial')
- legend('polynomial','nodes')
- ylim([1 5]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement