diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2024-12-23 21:13:51 +0100 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2024-12-23 21:13:51 +0100 |
| commit | a166aa339da97c656fc3e0dc4063589e5752386f (patch) | |
| tree | c3c7b8e007ee9e4d38e27a171eb8c7b6162e2ef6 /Functions | |
| parent | 9a96febe0fd0c92d2166851b69677ace2092ed56 (diff) | |
Fix equation
Diffstat (limited to 'Functions')
| -rw-r--r-- | Functions/falsePosition.m | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Functions/falsePosition.m b/Functions/falsePosition.m index d2cb776..9e4a236 100644 --- a/Functions/falsePosition.m +++ b/Functions/falsePosition.m @@ -20,26 +20,26 @@ if nargin < 3, error('Too few arguments: at least 3 needed'), end if nargin < 4 | isempty(es), es = 0.0001; end if nargin < 5 | isempty(maxit), maxit = 200; end -iter=0; -ea=100; -xr= xl; +iter = 0; +ea = 100; +xr = xl; while(1) - xrold= xr; + xrold = xr; iter = iter + 1; - xr=xu-func(xu)*(xl-xu)/(func(xl)-func(xu)); - if xr~=0 + xr = (xl * func(xu) - xu * func(xl))/(func(xu)-func(xl)); + if xr~= 0 ea = abs((xr-xrold)/xr)*100; end if func(xl)*func(xr)<0 - xl=xr; + xl = xr; else - xl=xr; + xl = xr; end if iter == maxit | ea <= es, break, end end root = xr; -fx=func(xr,varargin{:}); -ea=ea; -iter=iter; -end
\ No newline at end of file +fx = func(xr,varargin{:}); +ea = ea; +iter = iter; +end |
