Advertisement
UF6

Problem III a

UF6
Nov 24th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.54 KB | None | 0 0
  1. function p=Q3a(p0, tol, N)
  2.  
  3.     i=1;
  4.    
  5.    while i<=N
  6.        
  7.        n=ceil(sqrt(((p0^4))/(6*sqrt(pi)*tol))^1/2)
  8.        h=p0/n;
  9.        u=(1:n-1)*h;
  10.        fexp=exp((-u.^2)/2);
  11.        s=sum(fexp);
  12.        S=(h/2)*(1+2*s+exp((-p0^2)/2));      
  13.        
  14.        f=(2/sqrt(pi))*S-1;
  15.        df=(2/sqrt(pi))*exp((-p0^2)/2);
  16.        
  17.        p=p0-(f/df)
  18.        if abs(p-p0)<=tol
  19.            disp(['The error is less than the given tolerance after ' num2str(i) ' iterations'])
  20.            return
  21.        end
  22.        
  23.        i=i+1;
  24.        p0=p;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement