diff --git a/Schrick-Noah_Homework-5.R b/Schrick-Noah_Homework-5.R index bd590fa..1014a21 100644 --- a/Schrick-Noah_Homework-5.R +++ b/Schrick-Noah_Homework-5.R @@ -35,8 +35,6 @@ bvec <- solve(A.2, yvec) all.equal(as.matrix(yvec), A.2 %*% bvec) # use all.equal instead of == (tols and storage type) # EX: identical(as.double(8), as.integer(8)) returns FALSE - - # d. Plot poly_predict <- function(x){ # given input x, returns polynomial prediction @@ -51,12 +49,36 @@ lines(xdomain,y.predict,type="l") # overlay solid line ## 3. Kirchoff # a. Create vectors # Resistance vec -# Voltage vec +Rvec <- c(5,10,5,15,10,20) # Matrix A and vector b +A.3a <- matrix(c(Rvec[1],0,0,0,Rvec[5],Rvec[6], + 0,Rvec[2],Rvec[3],Rvec[4],-Rvec[5],0, + 1,-1,0,0,-1,0, + 0,1,-1,0,0,0, + 0,0,1,-1,0,0, + 0,0,0,1,1,-1) + ,nrow=6) +A.3a <- t(A.3a) # easier to conf that A is correct if def matrix as above then t() +V=200 +b.3vec <- c(V,0,0,0,0,0) + # Solve -# Show currents +i.a <- solve(A.3a,b.3vec) +i.a # b. Repeat a. Use V=200, and R=(5,10,5,15,0,20) +Rvec.b <- c(5,10,5,15,0,20) +A.3b <- matrix(c(Rvec.b[1],0,0,0,Rvec.b[5],Rvec.b[6], + 0,Rvec.b[2],Rvec.b[3],Rvec.b[4],-Rvec.b[5],0, + 1,-1,0,0,-1,0, + 0,1,-1,0,0,0, + 0,0,1,-1,0,0, + 0,0,0,1,1,-1) + ,nrow=6) +A.3b <- t(A.3b) # easier to conf that A is correct if def matrix as above then t() + +i.b <- solve(A.3b,b.3vec) +i.b ## 4. Schrodinger eq #a. Solve and plot the 1d quantum harmonic oscillator wave function