Skip to content

Commit

Permalink
Part F
Browse files Browse the repository at this point in the history
  • Loading branch information
Maliniak committed Dec 13, 2017
1 parent a59d83a commit e7b92db
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Part E/SE_diff.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down
37 changes: 37 additions & 0 deletions Part F/bisect.m
Original file line number Diff line number Diff line change
@@ -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{:});
25 changes: 25 additions & 0 deletions Part F/membrane_solution.m
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions Part F/mod_secant.m
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions Part F/tension_sol.asv
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 6 additions & 0 deletions Part F/tension_sol.m
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e7b92db

Please sign in to comment.