B
    žµs^¤  ã               @   sH   d dl mZ d dlZd dlZd dlmZ ddde 	ej
¡ fdd„ZdS )é    Ni'  é   c       
      C   s*  dd„ }t  | ¡}d}xXt| ƒD ]L}|t ¡  }|t ¡  }|||ƒk rP|d7 }|| ||d   }	|	||< q W tjdd„ t| ƒD ƒ|ddt|ƒ d	 d
 tjd| gt |¡t |¡gdt|ƒ d	 d t 	d¡ t 
d¡ t ¡  t t |¡|d  t |¡|d  ¡ t dt|ƒ d ¡ d S )Nc             S   s    dt  t j¡ t  | d  ¡ S )Nr   )ÚnpÚsqrtÚpiÚexp)Úx© r   úC/Users/vegardjervell/Documents/6_semester/matmod/matmod10/mc_erf.pyÚerf_func   s    zplot.<locals>.erf_funcr   é   c             S   s   g | ]}|d  ‘qS )r   r   )Ú.0Úir   r   r	   ú
<listcomp>   s    zplot.<locals>.<listcomp>ÚgreenzCalculated value of erf(ú))ÚcolorÚlabelzExact value of erf()r   zValue of errorfunctionzNumber of trialsé   z.) using Monte Carlo method vs. the exact value)r   ÚzerosÚrangeÚrandomÚpltÚplotÚstrÚssÚerfÚylabelÚxlabelÚlegendÚylimÚtitle)
ÚNÚbÚy_maxr
   ÚIntegralZN_Ir   r   ÚyÚIr   r   r	   r      s"    
,0

(r   )Úmatplotlib.pyplotÚpyplotr   Únumpyr   r   Zscipy.specialÚspecialr   r   r   r   r   r   r   r	   Ú<module>   s   