-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask3.m
More file actions
38 lines (31 loc) · 678 Bytes
/
task3.m
File metadata and controls
38 lines (31 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function f = task103 (input1, input2)
function y = f(x)
y = x.^2 - 2;
end
a = 1;
b = 2;
e = 0.000001;
A = [];
while (b - a ) / 2 > e
c = (a * f(b) - b * f(a)) / (f(b) - f(a));
A =[A; c];
if f (c) == 0
break;
elseif f(a) * f(c) < 0
b = c;
else f(b) * f(c) < 0
a = c;
end
end
fprintf ('%f\n', A (end));
x = linspace (1, 2, 50);
y = f(x);
plot (x, y, 'g');
grid on;
hold on;
plot(A, f(A), 'rd');
xlabel('Values of x');
ylabel('Functional values');
title('False-Position Method');
legend('Functional values ', 'Roots');
endfunction