diff --git a/README.md b/README.md index c17a81a..538c5a3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # 07_final_project -### Part A +## Part A +### Problem Statement +Create a function called membrane_solution3 that uses the central finite difference approximation to solve for the displacements of a membrane with 3 x 3 interior nodes. The function should take the pressure (P) and tension (T) as inputs and output a column vector, w. + ``` matlab function [w] = membrane_solution3(T,P) % Set up initial matrix % T = given tension (microNewton/micrometer) @@ -21,14 +24,20 @@ function [w] = membrane_solution3(T,P) % Set up initial matrix end ``` -### Part B +## Part B +### Problem Statement +Using the function from part A as well as a given tension of 0.006 uN/um and a given pressure of 0.001 MPa, solve for w and plot the result in 3 dimensions + ``` matlab [w] = membrane_solution3(0.006,0.001); ``` ![3x3 Interior Nodes](./figures/figure1.png) -### Part C +## Part C +### Problem Statement +Create a function called membrane_solution that uses the central finite difference approximation to solve for the displacements of a membrane with n x n interior nodes. The function should take the pressure (P), tension (T), and number of interior nodes (n) as inputs and output the column vector, w. + ```matlab function [w] = membrane_solution(T,P,n)% Set up initial matrix % T = given tension (microNewton/micrometer) @@ -50,7 +59,8 @@ function [w] = membrane_solution(T,P,n)% Set up initial matrix end ``` -### Part D +## Part D +### Problem Statement ``` matlab [w] = membrane_solution(0.006,0.001,10) ``` diff --git a/SE_diff.m b/SE_diff.m index cbf4968..090e813 100644 --- a/SE_diff.m +++ b/SE_diff.m @@ -1,91 +1,63 @@ -function [pw_se,w]=SE_diff(T,P,n) -w = membrane_solution31(T,P,n); -A = zeros(n,n); -h = zeros(n,1); -m = n+1; %Represents the number of nodes - -%Top Left Corner Interior Node -for i = 2+m - A(i,i)=1; - A(i,i-1)=0; - A(i,i+m)=1; - A(i,i+m-1)=0; - h(i) = 10; -end -%Top Right Corner Interior Node -for i = m*2-1 - A(i,i)=1; - A(i,i-1)=1; - A(i,i+m)=1; - A(i,i+m-1)=1; - h(i) = 10; -end -%Bottom Left Corner Interior Node -for i = m*m-(2*m)+1 - A(i,i)=1; - A(i,i-1)=0; - A(i,i+m)=0; - A(i,i+m-1)=0; - h(i) = 10; -end -%Bottom Right Corner Interior Node -for i = (m*m)-m-1 - A(i,i)=1; - A(i,i-1)=1; - A(i,i+m)=0; - A(i,i+m-1)=0; - h(i) = 10; -end - -%The following represent the values for the interior nodes - -%Top Interior Row -for i = 3+m:m*2-2 - A(i,i)=1; - A(i,i-1)=1; - A(i,i+m)=1; - A(i,i+m-1)=1; - h(i) = 10; -end -%Bottom Interior Row -for i = m*m-(2*m)+2:(m*m)-m-2 - A(i,i)=1; - A(i,i-1)=1; - A(i,i+m)=0; - A(i,i+m-1)=0; - h(i) = 10; -end -%Left Interior Column -for i = (2*m)+2,(2*m)+2:(m*m)-(2*m)+2 - A(i,i)=1; - A(i,i-1)=0; - A(i,i+m)=1; - A(i,i+m-1)=0; - h(i) = 10; -end -%Right Interior Column -for i = (3*m)-1,(2*m)+2:(m*m)-(2*m)+2 - A(i,i)=1; - A(i,i-1)=1; - A(i,i+m)=1; - A(i,i+m-1)=1; - h(i) = 10; -end -%Inerior Nodes -for i = (2*m)+3:(3*m)-2,(2*m)+3:(m*m)-(3*m)+3 - A(i,i)=1; - A(i,i-1)=1; - A(i,i+m)=1; - A(i,i+m-1)=1; - h(i) = 10; -end - - -dw_dx = (A(i,i)-A(i-1)+A(i,i+m)-A(i,i+m-1))/(2.*h); -dw_dx' +function [pw_se,w] = SE_diff(T,P,n) + + % Call function from part c to obtain vector w + w = membrane_solution(T,P,n); + % Create All Nodes Matrix (Interior & Exterior) + m = zeros(n+2); + c = vec2mat(w,n); % Vector w rearranged to n x n matrix. + m(2:n+1,2:n+1) = c; % insert matrix c into middle of m matrix + % m = symmetric matrix + + h = 10/(n+1); % h = delta_x = delta_y (micron) + + % Compute w bar + w_bar = zeros(n+1,n+1); + for i = 1:n+1 + for j = 1:n+1 + w_bar(i,j) = (m(i,j)+m(i,j+1)+m(i+1,j)+m(i+1,j+1))/4; + end + end + + % Left side of the equation + left_side = zeros(n+1,n+1); + for i = 1:(n+1)^2 + left_side(i) = P * h^2*w_bar(i); + end + L = sum(sum(left_side)); + + % Compute dw_dx + dx = zeros(n+2,n+1); + for i = 2:n+2 + dx(:,i-1)= (m(:,i)-m(:,i-1))/(h); + end + + dw_dx = zeros(n+1,n+1); + for i = 1:n+1 % rows + for j = 1:n+1 % columns + dw_dx(i,j) = (dx(i,j)+dx(i+1,j))/2; + end + end -end + % Compute dw_dy + dy = zeros(n+1,n+2); + for i = 2:n+2 + dy(i-1,:)= (m(i-1,:)-m(i,:))/(h); + end + dw_dy = zeros(n+1,n+1); + for i = 1:n+1 % rows + for j = 1:n+1 % columns + dw_dy(i,j) = (dy(i,j)+dy(i,j+1))/2; + end + end + + right_side = zeros(n+1,n+1); + for i = 1:(n+1)^2 + right_side(i) = (0.25*(dw_dx(i))^4+0.25*(dw_dy(i))^4+0.5*(dw_dx(i)*dw_dy(i))^2); + end + R = sum(sum(right_side)); + R = (1000*10^3*0.3*10^-3*h^2)/(2*(1-0.31^2))*R; - \ No newline at end of file + pw_se = R - L; +end \ No newline at end of file diff --git a/membrane_solution.m b/membrane_solution.m index d0b1734..218ebae 100644 --- a/membrane_solution.m +++ b/membrane_solution.m @@ -9,7 +9,7 @@ % Solve for unknown matrix, w y = -(10/(n+1))^2*(P/T)*ones(n^2,1); %output vector - w = k\y; %solves for w in microm + w = k\y; %solves for w in micron [x,y] = meshgrid(0:10/(n+1):10,0:10/(n+1):10); z = zeros(size(x));