Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Lab4. It is ready

  • Loading branch information...
commit effad400e88c3a95900a1978781ed2e6190c4c83 0 parents
@Paulche authored
22 lab4/d_solve.m
@@ -0,0 +1,22 @@
+function root = d_solve(from, till, num_steps)
+ y = f;
+
+ for n = 1:num_steps
+ middle = (from + till)/2;
+
+ middle_val = y(middle);
+ left_val = y(from);
+
+ if middle_val == 0
+ break;
+ else
+ if sign(left_val) == sign(middle_val)
+ from = middle;
+ else
+ till = middle;
+ end
+ end
+ end
+
+ root = middle;
+end
3  lab4/df.m
@@ -0,0 +1,3 @@
+function y = df()
+ y = matlabFunction(diff(linput));
+end
3  lab4/f.m
@@ -0,0 +1,3 @@
+function y = f()
+ y = matlabFunction(linput);
+end
3  lab4/linput.m
@@ -0,0 +1,3 @@
+function f = linput(x)
+ f = sym('(log(x)+x)*cos(x^2)+1/3');
+end
18 lab4/n_solve.m
@@ -0,0 +1,18 @@
+function root = n_solve(num_steps, start)
+ y = f;
+ dy = df;
+
+ x = start;
+
+ for n = 1:num_steps
+
+ if y(x) == 0
+ break;
+ else
+ x = x - y(x)/dy(x);
+ end
+
+ end
+
+ root = x;
+end
Please sign in to comment.
Something went wrong with that request. Please try again.