From 2d6cd40bf75d91d5a32df874b951a13644abaa7d Mon Sep 17 00:00:00 2001 From: Leahy Date: Thu, 14 Dec 2017 17:34:17 -0500 Subject: [PATCH] 1 --- README.md | 2 ++ bisect.m | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 bisect.m diff --git a/README.md b/README.md index c88c1e8..1ea9650 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ end ## Part D ### Problem Statement +Solve for the vector w using the function from part C with a P value of 0.001, T value of 0.006, and 10 interior nodes. The 3 dimensional coordinates will then be plotted. + ``` matlab [w] = membrane_solution(0.006,0.001,10) ``` diff --git a/bisect.m b/bisect.m new file mode 100644 index 0000000..f4b17cd --- /dev/null +++ b/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{:});