User:Alex G. Benedict/Notebook/Physics 307L: Junior Lab/SimpleSearchScript

The following script takes 3 column vectors, and finds the values of Rcoeff, and Voltcoeff which minimize the average relative error.

The data for the three vectors can be downloaded here.

The suffixes NG, KH, AGB refer to Nathan Gianni, Kristen Harriger, and Alex Benedict, whose data I used in finding a good value of the voltage coefficient and radius coefficient.

Actualem=175882017000;

Voltcoeff=0:0.05:1;

Rcoeff=0:0.05:50;

for i=1:length(Rcoeff) for j=1:length(Voltcoeff) for k=1:length(R) top=2*(Voltcoeff(j)*V(k)-Rcoeff(i)*R(k)); bottom=(B(k)^2*R(k)^2); emmodeled(i,j,k)=top/bottom; end end end

aveNG=mean(emmodeled(:,:,1:18),3);

aveKH=mean(emmodeled(:,:,19:39),3);

aveAGB=mean(emmodeled(:,:,39:end),3);

ave=mean(emmodeled,3);

errorNG=Actualem-aveNG;

errorKH=Actualem-aveKH;

errorAGB=Actualem-aveAGB;

error=Actualem-ave;

relerrNG=abs(errorNG)/Actualem;

relerrKH=abs(errorKH)/Actualem;

relerrAGB=abs(errorAGB)/Actualem;

relerr=abs(error)/Actualem;

[CNG,ING]=min(relerrNG);

[CKH,IKH]=min(relerrKH);

[CAB,IAB]=min(relerrAGB);

[C,I]=min(relerr);

[ing,jng]=ind2sub(size(relerrNG),ING);

[ikh,jkh]=ind2sub(size(relerrNG),IKH);

[iagb,jagb]=ind2sub(size(relerrNG),IAB);

[i,j]=ind2sub(size(relerr),I);

[Rcoeff(ing),Voltcoeff(jng)]

[Rcoeff(ikh),Voltcoeff(jkh)]

[Rcoeff(iagb),Voltcoeff(jagb)]

[Rcoeff(i),Voltcoeff(j)]