function [xvalue,lambda,slambda,xx,sxx,cosangle,residual,tloc] = sampleMinEig(Q,DQ,yMin,yMax,nrSamples,lambdasfem,xsfem); %%%% compares the result of stochastic fem with the simulation tsfem=0; tsample=0; n=max(size(Q)); for i=1:nrSamples %%%%% draw a random number and scale it; omega=-1+(2/nrSamples)*i; xvalue(i)=omega; t=cputime; %spQ=sparse(Q+omega*DQ); %nnz(spQ) %[U,S]=eigs(spQ,1,'SA'); [U,S]=eig(Q+omega*DQ); tloc(i)=cputime-t tsample=tsample+tloc(i); [lambda(i),index]=min(diag(S)); x=U(:,index); x=x/norm(x); t=cputime; tic; slambda(i)=lambdasfem(1)*Leg0(omega)+lambdasfem(2)*Leg1(omega)+lambdasfem(3)*Leg2(omega)+lambdasfem(4)*Leg3(omega)+lambdasfem(5)*Leg4(omega); sx0=xsfem(:,1)*Leg0(omega)+xsfem(:,2)*Leg1(omega); sx=sx0+xsfem(:,3)*Leg2(omega)+xsfem(:,4)*Leg3(omega)+xsfem(:,5)*Leg4(omega); residual(i)=norm((Q+omega*DQ)*sx-slambda(i)*sx); tloc1=toc tsfem=tsfem+tloc1; tsample tsfem if (x'*sx < 0) x=-x; end xx(:,i)=x; sxx(:,i)=sx; lxx(:,i)=sx0; cosangle(i)=(x'*sx)/(norm(x)*norm(sx)); end tsample tsfem