Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
part of question 2
three methods and chart
  • Loading branch information
tjc14008 committed Oct 5, 2017
1 parent 8728f8c commit e4eeaef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
@@ -1,2 +1,25 @@
# 02_roots_and_optimization
Repository for homework 2

Question 2
'''matlab
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,fx,ea,iter]=falsepos(cat_cable,900,910,0.00001)
'''
'''matlab
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,fx,ea,iter]=bisect(cat_cable,908,909,0.00001)
'''
'''matlab
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,ea,iter]=mod_secant(cat_cable,900,910,0.00001)
'''


'''matlab
| solver | initial guess(es) | ea | number of iterations|
| --- | --- | --- | --- |
|falsepos | 900, 910 | 0.00001| 4 |
|mod_secant | 900, 910 | 0.00001| 50 |
|bisect | 900, 910 | 0.00001| 17 |
'''
2 changes: 2 additions & 0 deletions bisect_cat.m
@@ -0,0 +1,2 @@
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,fx,ea,iter]=bisect(cat_cable,900,910,0.00001)
2 changes: 1 addition & 1 deletion falsepos.m
Expand Up @@ -23,7 +23,7 @@ while (1)
xrold = xr;
xr = (xl + xu)/2;
% xr = (xl + xu)/2; % bisect method
xr=xu - (f_m(xu)*(xl-xu))/(f_m(xl)-f_m(xu)); % false position method
xr=xu - (func(xu)*(xl-xu))/(func(xl)-func(xu)); % false position method
iter = iter + 1;
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl,varargin{:})*func(xr,varargin{:});
Expand Down
2 changes: 2 additions & 0 deletions falsepos_cat.m
@@ -0,0 +1,2 @@
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,fx,ea,iter]=falsepos(cat_cable,900,910,0.00001)
2 changes: 2 additions & 0 deletions mod_secant_cat.m
@@ -0,0 +1,2 @@
cat_cable = @(T) -35+T/10.*cosh(10./T*30)+30-T/10;
[root,ea,iter]=mod_secant(cat_cable,900,910,0.00001)

0 comments on commit e4eeaef

Please sign in to comment.