Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % решение интеграла
- n=20;
- F=zeros(1,n);
- J=zeros(1,n);
- res=zeros(1,n-2);
- for i=2:n-1
- F(i)=vect(i);
- f1=@(x) log(i^2*x+1)/(1+x*2+i*x^2);
- J(i)=quad(f1,0,5);
- res(i-1)=abs(J(i)-F(i));
- endfor
- F(n)=0;
- F(1)=1;
- E=0.001;
- X=zeros(n,1);
- F=F'
- A=zeros(n,n);
- for i=2:n-1
- A(i,i-1)=1;
- A(i,i)=-(4+cos(i^2)/(i^2+2));
- A(i,i+1)=1;
- endfor
- A(1,1)=1;
- A(n,n)=1;
- xx=(A^-1)*F;
- N=length(F); % размер вектора
- X=zeros(n,1); % формирование массива нулей Nx1
- X1=zeros(n,n);
- nn=0; % Счетчик итераций
- R=F;% При начальном приближении X=0
- ss=1; % признак итераций
- x0=0;
- for i=1:N
- X(i,1)=F(i,1)/A(i,i);
- endfor
- while ss % norm (R, inf)/nf > epsilon
- nn=nn+1;
- if nn>1000
- ss=0; % аварийный конец итераций
- break
- end
- R=F-A*X;
- B=A*R;
- tau=(B'*R)/(B'*B);
- X=X+tau*R;
- X1(:,nn)=X;
- norma=abs(norm(X-x0));
- if norma <=E
- ss=0; % конец итераций, решение получено
- end
- x0=X;
- end
- norma
- nn
- X
- xx
- res1=zeros(1,nn);
- r1=zeros(n,nn);
- for i=1:nn-1
- r1(:,i)=abs(xx-X1(:,i));
- for k=1:N
- res1(i)=res1(i)+r1(k,i)^2;
- endfor
- res1(i)=sqrt(res1(i));
- endfor
- aa=(1:1:nn);
- aaa=(1:1:N-2);
- size(aaa);
- size(res) ;
- subplot(2,1,1)
- plot(aa,res1)
- title ( 'System' ) ;
- grid on
- subplot(2,1,2)
- plot(aaa,res)
- title ( 'Integral' ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement