In the previous post, https://autarkaw.wordpress.com/2010/09/01/using-int-and-solve-to-find-inverse-error-function-in-matlab/, we found the inverse error function by using the integral and solve MATLAB functions. In this blog, we find the inverse error function by using interpolation.

The value of erf(x) is given at discrete data points of x, and we use spline interpolation to find the value of x at a given value of erf(x). The given data points of (x,erf(x)) are (0,0), (0.1,0.1125), (0.25,0.2763), (0.75,0.7112), (1.0,0.8427), (1.5,0.9661), (2.0,0.9953), (5.0,1.000).

It is better to **download** (right click and save target) the program as single quotes in the pasted version do not translate properly when pasted into a mfile editor of MATLAB or you can read the **html version **for clarity and sample output.

%% FINDING INVERSE ERROR FUNCTION

% In a previous blog at autarkaw.wordpress.com (Sep 1, 2010), we set up a

% nonlinear equation to find the inverse error function.

% In this blog, we will solve this equation

% by using interpolation.

% The problem is given at

% http://nm.mathforcollege.com/blog/inverseerror.pdf

% and we are solving Exercise 2 of the pdf file.

%% TOPIC

% Finding inverse error function

%% SUMMARY

% Language : Matlab 2008a;

% Authors : Autar Kaw;

% Mfile available at

% http://nm.mathforcollege.com/blog/inverse_erf_interp_matlab.m;

% Last Revised : October 4 2010

% Abstract: This program shows you how to find the inverse error function

% using interpolation

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 https://autarkaw.wordpress.com’)

disp(‘ ‘)

disp(‘MFILE SOURCE’)

disp(‘ http://nm.mathforcollege.com/blog/inverse_erf_interp_matlab.m’)

disp(‘ ‘)

disp(‘PROBLEM STATEMENT’)

disp(‘ http://nm.mathforcollege.com/blog/inverseerror.pdf Exercise 2′)

disp(‘ ‘)

disp(‘LAST REVISED’)

disp(‘ October 4, 2010’)

disp(‘ ‘)

%% INPUTS

% Value of error function

erfx=0.1125;

% Table of erf(x) vs x

xx=[0 0.1 0.25 0.75 1.0 1.5 2.0 5.0];

erfxx=[0 0.1125 0.2763 0.7112 0.8427 0.9661 0.9953 1.0000];

%% DISPLAYING INPUTS

disp(‘INPUTS’)

fprintf(‘ Inverse error function is to be found for= %g’,erfx)

disp(‘ ‘)

disp(‘ Given erf(x) vs x values’)

disp(‘_______________________’)

disp(‘ x erfx ‘)

disp(‘________________________’)

dataval=[xx;erfxx]’;

disp(dataval)

%% CODE

if erfx>1.0 | erfx<0

disp(‘Invalid value. erf(x) only takes values in [0,1] range’)

else

inverse_erf=interp1(erfxx,xx,erfx,’cubic’);

%% DISPLAYING OUTPUTS

disp(‘OUTPUTS’)

fprintf(‘ Value of inverse error func from this mfile is= %g’,inverse_erf)

fprintf(‘ \n Value of inverse error func from MATLAB is = %g’,erfinv(erfx))

disp(‘ ‘)

end

__________________________________________________

### Like this:

Like Loading...