%% FINDING INVERSE ERROR FUNCTION
% In a previous blog at autarkaw.wordpress.com (August 24, 2010), 
% we set up a nonlinear equation to find the inverse error function.
% In this blog, we will solve this equation.
% The problem is given at
% http://numericalmethods.eng.usf.edu/blog/inverseerror.pdf
% and we are solving Exercise 1 of the pdf file.

%% TOPIC
% Finding inverse error function

%% SUMMARY

% Language : Matlab 2010a; 
% Authors : Autar Kaw; 
% Mfile available at
% http://numericalmethods.eng.usf.edu/blog/inverse_erf_matlab.m; 
% Last Revised : August 27, 2010
% Abstract: This program shows you how to find the inverse error function
clc
clear all

%% INTRODUCTION

disp('ABSTRACT')
disp('   This program shows you how to')
disp('   find the inverse error function')
disp(' ')
disp('AUTHOR')
disp('   Autar K Kaw of http://autarkaw.wordpress.com')
disp(' ')
disp('MFILE SOURCE')
disp('   http://numericalmethods.eng.usf.edu/blog/inverse_erf_matlab.m')
disp('  ')
disp('PROBLEM STATEMENT')
disp('   http://numericalmethods.eng.usf.edu/blog/inverseerror.pdf')
disp('        Exercise 1')
disp(' ')
disp('LAST REVISED')
disp('   August 27, 2010')
disp(' ')

%% INPUTS
% Value of error function
erfx=0.5;

%% DISPLAYING INPUTS

disp('INPUTS')
fprintf(' The value of error function= %g',erfx)
disp('  ')
disp('  ')

%% CODE
syms t x
inverse_erf=solve(int(2/sqrt(pi)*exp(-t^2),t,0,x)-erfx);
inverse_erf=double(inverse_erf);


%% DISPLAYING OUTPUTS

disp('OUTPUTS')
fprintf(' Value of inverse error function from mfile is= %g',inverse_erf)
fprintf('\n Value of inverse error function using erfinv is= %g',erfinv(erfx))
disp('  ')