diff --git a/Part E/SE_diff.m b/Part E/SE_diff.m index f68b909..e7202ff 100644 --- a/Part E/SE_diff.m +++ b/Part E/SE_diff.m @@ -1,5 +1,5 @@ function [pw_se,w]=SE_diff(T,P,n) -E = 1; %TPa Units may need to be changed +E = 1e6; %TPa Units may need to be changed v = .31; %Poissons ratio t = .3; %nm h = 10/(n+1); %nm diff --git a/Part F/bisect.m b/Part F/bisect.m new file mode 100644 index 0000000..47ee7ec --- /dev/null +++ b/Part F/bisect.m @@ -0,0 +1,37 @@ +function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin) +% bisect: root location zeroes +% [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...): +% uses bisection method to find the root of func +% input: +% func = name of function +% xl, xu = lower and upper guesses +% es = desired relative error (default = 0.0001%) +% maxit = maximum allowable iterations (default = 50) +% p1,p2,... = additional parameters used by func +% output: +% root = real root +% fx = function value at root +% ea = approximate relative error (%) +% iter = number of iterations +if nargin<3,error('at least 3 input arguments required'),end +test = func(xl,varargin{:})*func(xu,varargin{:}); +if test>0,error('no sign change'),end +if nargin<4||isempty(es), es=0.0001;end +if nargin<5||isempty(maxit), maxit=50;end +iter = 0; xr = xl; ea = 100; +while (1) + xrold = xr; + xr = (xl + xu)/2; + iter = iter + 1; + if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end + test = func(xl,varargin{:})*func(xr,varargin{:}); + if test < 0 + xu = xr; + elseif test > 0 + xl = xr; + else + ea = 0; + end + if ea <= es || iter >= maxit,break,end +end +root = xr; fx = func(xr, varargin{:}); \ No newline at end of file diff --git a/Part F/membrane_solution.m b/Part F/membrane_solution.m new file mode 100644 index 0000000..ae80fce --- /dev/null +++ b/Part F/membrane_solution.m @@ -0,0 +1,25 @@ +function [w] = membrane_solution(T,P,n) + % T = Tension (microNewton/micrometer) + % P = Pressure (MPa) + % n = # of interior nodes + + od = ones(n^2-1,1); + od(n:n:end) = 0; + k = -4*diag(ones(n^2,1))+diag(ones((n^2)-n,1),n)+diag(ones((n^2)-n,1),-n)+diag(od,1)+diag(od,-1); + + y = -(10/(n+1))^2*(P/T)*ones(n^2,1); + w = k\y; + + % Solves for displacement (micrometers) + % Output w is a vector + % Solution represents a 2D data set w(x,y) + + [x,y] = meshgrid(0:10/(n+1):10,0:10/(n+1):10); + z = zeros(size(x)); + z(2:end-1,2:end-1) = reshape(w,[n n]); + surf(x,y,z) + title('Membrane Displacement') + zlabel('Displacement (micrometer)') + + % Membrane displacement is shown on chart +end \ No newline at end of file diff --git a/Part F/mod_secant.m b/Part F/mod_secant.m new file mode 100644 index 0000000..b74f181 --- /dev/null +++ b/Part F/mod_secant.m @@ -0,0 +1,30 @@ +function [root,ea,iter]=mod_secant(func,dx,xr,es,maxit,varargin) +% newtraph: Modified secant root location zeroes +% [root,ea,iter]=mod_secant(func,dfunc,xr,es,maxit,p1,p2,...): +% uses modified secant method to find the root of func +% input: +% func = name of function +% dx = perturbation fraction +% xr = initial guess +% es = desired relative error (default = 0.0001%) +% maxit = maximum allowable iterations (default = 50) +% p1,p2,... = additional parameters used by function +% output: +% root = real root +% ea = approximate relative error (%) +% iter = number of iterations +if nargin<3,error('at least 3 input arguments required'),end +if nargin<4 || isempty(es),es=0.0001;end +if nargin<5 || isempty(maxit),maxit=50;end +iter = 0; +while (1) + xrold = xr; + dfunc=(func(xr+dx)-func(xr))./dx; + xr = xr - func(xr)/dfunc; + iter = iter + 1; + if xr ~= 0 + ea = abs((xr - xrold)/xr) * 100; + end + if ea <= es || iter >= maxit, break, end +end +root = xr; \ No newline at end of file diff --git a/Part F/tension_sol.asv b/Part F/tension_sol.asv new file mode 100644 index 0000000..e513227 --- /dev/null +++ b/Part F/tension_sol.asv @@ -0,0 +1,7 @@ +function T = tension_sol(P,n) +num = length(n) +for i = 1:nu +od = ones(n^2-1,1); +od(n:n:end) = 0; +k = -4*diag(ones(n^2,1))+diag(ones((n^2)-n,1),n)+diag(ones((n^2)-n,1),-n)+diag(od,1)+diag(od,-1); +y = -(10/(n+1))^2*(P/T)*ones(n^2,1); \ No newline at end of file diff --git a/Part F/tension_sol.m b/Part F/tension_sol.m new file mode 100644 index 0000000..0e95ee4 --- /dev/null +++ b/Part F/tension_sol.m @@ -0,0 +1,6 @@ +function T = tension_sol(P,n) +num = length(n); +for i = 1:num + y =@(T) (P./T)+3.6534e+04; + [root,fx,ea,iter]=bisect(y,0,.006) +end \ No newline at end of file