Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [sum] = vecsum(RV)
- %this function will input a row vector and return a sum of all the elements
- L = length(RV);
- i = 1;
- sum = 0;
- while i <= L
- sum = sum + RV(i);
- i = i + 1;
- end
- end
- function [A,B,dA,dB] = wregression(x,y,dy)
- %this function calculates slope, y intercept and uncertainty in both
- %it also assumes that x, y and dy are of the same length
- w = 1./(dy.^2);
- %First we get the sums we will need to find our return values
- w_sum = vecsum(w);
- wy_sum = vecsum(w.*y);
- wx_sum = vecsum(w.*x);
- wxy_sum = vecsum(w.*x.*y);
- wx2_sum = vecsum(w.*(x.^2));
- %Now we find the value of D to be used later
- D = (w_sum*wx2_sum) - (wx_sum^2);
- %Here we use our sums along with D to find the return values
- A = ((wx2_sum*wy_sum)-(wx_sum*wxy_sum))/D;
- B = ((w_sum*wxy_sum)-(wx_sum*wy_sum))/D;
- dA = sqrt(wx2_sum/D);
- dB = sqrt(w_sum/D);
- end
- function regressionplot(x,y,dy)
- hold on
- figure(1)
- errorbar(x,y,dy,'rx')
- xfit = linspace(0,5);
- [A,B,dA,dB] = wregression(x,y,dy);
- yfit = xfit*B + A;
- plot(xfit,yfit)
- end
- function [z2] = zSq(V,I);
- z2 = (V./I).^2;
- end
- function [R L dR dL] = indRes(f,V,I,dV,dI)
- f=[152 361 568 823 1031 1358]; % frequency [Hz];
- V=[1.63 2.01 2.47 3.00 3.34 3.75]; % inductor RMS voltage [V]
- I=[0.0615 0.0593 0.056 0.0512 0.0472 0.0413]; % inductor RMS current [A]
- dV=V*0.005+0.02; % Uncertainty in the voltage measurements [V]
- dI=I*0.0075+0.0002; % Uncertainty in the current measurements [A]
- radF = (2*f*pi).^2;
- z2 = zSq(V,I);
- dZSq=((zSq(V+dV,I)-zSq(V,I)).^2+(zSq(V,I+dI)-zSq(V,I)).^2).^0.5;
- [R2,L2,dR2,dL2] = wregression(radF,z2,dZSq);
- R = R2^0.5;
- L = L2^0.5;
- dR = abs((R2+dR2)^0.5 - (R2)^0.5);
- dL = abs((L2+dL2)^0.5 - (L2)^0.5);
- end
- function [A B dA dB] = capa(f,V,I,dV,dI)
- f=[113 124 212 238 294 350 395 489]; % frequency [Hz]
- V=[7.39 7.47 7.46 7.35 7.36 7.35 7.44 7.43]; % Capacitor RMS Voltage [V]
- I=[2.51 2.73 4.82 5.41 6.61 7.81 8.91 11.2]*10^-3; % RMS Current [A]
- dV=V*0.005+0.02; % Experimental Uncertainty in Voltage Measurements [V]
- dI=I*0.0075+0.0002; % Uncertainty in Current [A]
- radF = (2*f*pi).^2;
- xvals = 1./radF
- z2 = zSq(V,I);
- dZSq=((zSq(V+dV,I)-zSq(V,I)).^2+(zSq(V,I+dI)-zSq(V,I)).^2).^0.5;
- [R2,cap2,dR2,dCap2] = wregression(xvals,z2,dZSq);
- R = R2^0.5;
- cap = cap2^-0.5;
- dR2 = abs((R2+dR2)^0.5 - (R2)^0.5);
- dCap2 = abs((1/(cap2+dCap2))^0.5 - (1/cap2)^0.5);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement