Está en la página 1de 5

%% Implementacion del metodo de Secante problema 5

clc, clear all;


func = @(x) (x^2)+x+(0.4*(nthroot(x,-3)))-1;
options = optimset('display', 'iter');
%Graficar la funcion func.
fplot(func, [-4 5], 'Color', [0 1 0], 'LineWidth',2);

Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize
your function to return an output with the same size and shape as the input arguments.

grid on

%Valor de las raices con la funcion fzero tomando valores aproximados.


[x, fx] = fzero(func, -2, options)

Search for an interval around -2 containing a sign change:


Func-count a f(a) b f(b) Procedure
1 -2 0.68252 -2 0.68252 initial interval
3 -1.94343 0.512963 -2.05657 0.858363 search
5 -1.92 0.44457 -2.08 0.933043 search
7 -1.88686 0.349686 -2.11314 1.0405 search
9 -1.84 0.219172 -2.16 1.19616 search
11 -1.77373 0.0419335 -2.22627 1.42368 search
12 -1.68 -0.194078 -2.22627 1.42368 search

Search for a zero in the interval [-1.68, -2.22627]:


Func-count x f(x) Procedure
12 -1.68 -0.194078 initial
13 -1.74553 -0.0308563 interpolation

1
14 -1.75766 0.000263779 interpolation
15 -1.75756 -1.20619e-06 interpolation
16 -1.75756 -4.67286e-11 interpolation
17 -1.75756 0 interpolation

Zero found in the interval [-1.68, -2.22627]


x = -1.7576
fx = 0

[x, fx] = fzero(func, 0.1, options)

Search for an interval around 0.1 containing a sign change:


Func-count a f(a) b f(b) Procedure
1 0.1 -0.0282261 0.1 -0.0282261 initial interval
3 0.0971716 -0.0233307 0.102828 -0.032799 search
5 0.096 -0.0212035 0.104 -0.0346033 search
7 0.0943431 -0.0180915 0.105657 -0.0370686 search
9 0.092 -0.0134741 0.108 -0.0403886 search
11 0.0886863 -0.00648552 0.111314 -0.0447671 search
12 0.084 0.00439828 0.111314 -0.0447671 search

Search for a zero in the interval [0.084, 0.111314]:


Func-count x f(x) Procedure
12 0.084 0.00439828 initial
13 0.0864435 -0.00142984 interpolation
14 0.085844 -3.16793e-05 interpolation
15 0.0858305 6.54941e-09 interpolation
16 0.0858305 -1.06559e-12 interpolation
17 0.0858305 0 interpolation

Zero found in the interval [0.084, 0.111314]


x = 0.0858
fx = 0

[x, fx] = fzero(func, 0.5, options)

Search for an interval around 0.5 containing a sign change:


Func-count a f(a) b f(b) Procedure
1 0.5 0.253968 0.5 0.253968 initial interval
3 0.485858 0.230727 0.514142 0.277789 search
5 0.48 0.221273 0.52 0.287823 search
7 0.471716 0.208078 0.528284 0.302177 search
9 0.46 0.189772 0.54 0.322804 search
11 0.443431 0.16461 0.556569 0.352618 search
13 0.42 0.130526 0.58 0.396042 search
15 0.386863 0.0854862 0.613137 0.459915 search
17 0.34 0.0287043 0.66 0.555022 search
18 0.273726 -0.0352906 0.66 0.555022 search

Search for a zero in the interval [0.273726, 0.66]:


Func-count x f(x) Procedure
18 0.273726 -0.0352906 initial
19 0.296818 -0.0154324 interpolation
20 0.314279 0.00138092 interpolation
21 0.312845 -5.4897e-05 interpolation
22 0.3129 -1.76426e-07 interpolation
23 0.3129 1.9007e-13 interpolation
24 0.3129 -1.11022e-16 interpolation
25 0.3129 -1.11022e-16 interpolation

Zero found in the interval [0.273726, 0.66]


x = 0.3129

2
fx = -1.1102e-16

%% Iniciando variables
%% Iniciando variables
x1 = 1; %Aproximacion Inicial de la Raiz 0.3129
x2 = 0.5; %Aproximacion Inicial de la Raiz 0.3129
x4 = 0.1; %Aproximacion Inicial de la Raiz 0.0858
x5 = 0.09; %Aproximacion Inicial de la Raiz 0.0858
x7= -1.65; %Aproximacion Inicial de la Raiz -1.7576
x8= -1.70; %Aproximacion Inicial de la Raiz -1.7576
es = 0.001; %Tolerancia
maxit = 50; %Maximo Numero de iteracciones
ea = 100;
eb = 100;
ec = 100;
iter = 1;
jter = 1;
zter = 1;
%% Inicio del Bucle
disp(' k xi xj ea(%)')

k xi xj ea(%)

while (1)
xrold1 = x1;
x3=x1;
x1 = x1-(func(x1)* ((x1 - x2)/(func(x1)-func(x2))));
x2 = x3;
fprintf('%3i%11.4f\t%11.4f\t%11.6f\n',iter,x1,x2,ea)
iter = iter + 1;
if x1 ~= 0
ea = abs((x1-xrold1)/x1)*100;
end
if ea <= es || iter >= maxit
break;
end
end

1 0.3892 1.0000 100.000000


2 0.3480 0.3892 156.939560
3 0.3173 0.3480 11.849693
4 0.3132 0.3173 9.655401
5 0.3129 0.3132 1.311661
6 0.3129 0.3129 0.100203
7 0.3129 0.3129 0.001030

root1 = x1;
fprintf('La primera raiz es: %11.4f\n',root1);

La primera raiz es: 0.3129

disp(' k xi xj ea(%)')

k xi xj ea(%)

3
while (1)
xrold2 = x4;
x6=x4;
x4 = x4-(func(x4)* ((x4 - x5)/(func(x4)-func(x5))));
x5 = x6;
fprintf('%3i%11.4f\t%11.4f\t%11.6f\n',jter,x4,x5,eb)
jter = jter + 1;
if x4 ~= 0
eb = abs((x4-xrold2)/x4)*100;
end
if eb <= es || jter >= maxit
break;
end
end

1 0.0851 0.1000 100.000000


2 0.0860 0.0851 17.552710
3 0.0858 0.0860 1.045578
4 0.0858 0.0858 0.157650
5 0.0858 0.0858 0.001463

root2 = x4;

fprintf('La segunda raiz es: %11.4f\n',root2);

La segunda raiz es: 0.0858

disp(' k xi xj ea(%)')

k xi xj ea(%)

while (1)
xrold3 = x7;
x9=x7;
x7 = x7-(func(x7)* ((x7 - x8)/(func(x7)-func(x8))));
x8 = x9;
fprintf('%3i%11.4f\t%11.4f\t%11.6f\n',zter,x7,x8,ec)
zter = zter + 1;
if x7 ~= 0
ec = abs((x7-xrold3)/x7)*100;
end
if ec <= es || zter >= maxit
break;
end
end

1 -1.7601 -1.6500 100.000000


2 -1.7575 -1.7601 6.252894
3 -1.7576 -1.7575 0.148014
4 -1.7576 -1.7576 0.006009

root3 = x7;
fprintf('La tercera raiz es: %11.4f\n',root3);

La tercera raiz es: -1.7576

4
5

También podría gustarte