function [est,v]=importance(f,g,Ginv,u) %runs a simulation on the function 'f" using importance density "g"(both character strings) and inverse c.d.f. "Ginverse" % outputs all estimators (should be averaged) and variance. % IM is the inverse cf of the importance distribution c.d.f. % run e.g. % [est,v]=importance('fn','2*(IM-.47)/(.53)^2;','.47+.53*sqrt(u);',rand(1,1000)); IM= eval(Ginv); %=.47+.53*sqrt(u); %IMdens is the density of the importance sampling distribution at IM IMdens=eval(g); %2*(IM-.47)/(.53)^2; FN=eval(strcat(f,'(IM)')); est=FN./IMdens; % mean(est) prrovides the estimator v=var(FN./IMdens); % this is the variance of the estimator per simulation %est=mean(est);