Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main
- format long;
- a=0; b=10; n=201;
- x=linspace(a,b,n);
- f=@(x) 0;
- K=@(x,s,y) (1+y^2)/(1+s^2);
- tol=1e-07;
- u=@(x) x;
- [y,x,iter]=Nonlin_VoltII_SimpleIter_Simpson(a,b,n,K,f,tol);
- er=norm(u(x)-y,inf)/norm(u(x),inf)
- plot(x,y,'o',x,u(x),'r');
- xlabel('x');
- ylabel('y');
- //function
- function [y,x,iter]=Nonlin_VoltII_SimpleIter_Simpson(a,b,n,K,f,tol,y0)
- x=linspace(a,b,n);
- h=x(2)-x(1);
- F=f(x);
- if(nargin<=6) y0=F;
- end
- if(nargin<=5) tol=1e-10;
- end
- y=ones(1,n)*inf;
- yk=y0;
- iter=0;
- yk(1)=F(1);
- y(1)=F(1);
- while(norm(yk-y,inf)/norm(yk,inf)>tol)
- y=yk;
- iter=iter+1;
- for i=2:n
- s=f(x(i));
- for j=1:(i-1)
- s=s+h*K(x(i),x(j),yk(j));
- end
- fun = @(y_i) (y_i-(h/2)*K(x(i),x(i),y_i)-s);
- yk(i)=fsolve(fun,yk(i-1));
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement