diff --git a/README.md b/README.md index 2990de4..e9dcc84 100644 --- a/README.md +++ b/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 | +''' diff --git a/bisect_cat.m b/bisect_cat.m new file mode 100644 index 0000000..df36339 --- /dev/null +++ b/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) \ No newline at end of file diff --git a/falsepos.m b/falsepos.m index 62a881c..2d010c8 100644 --- a/falsepos.m +++ b/falsepos.m @@ -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{:}); diff --git a/falsepos_cat.m b/falsepos_cat.m new file mode 100644 index 0000000..20922af --- /dev/null +++ b/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) diff --git a/mod_secant_cat.m b/mod_secant_cat.m new file mode 100644 index 0000000..422f31e --- /dev/null +++ b/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) \ No newline at end of file