Documente Academic
Documente Profesional
Documente Cultură
f(x) = 4x3 – x2 + 1
Newton-Raphson -1 -0.556393 5
1.2.- En los casos de Newton-Raphson el valor inicial creció hasta un millón de veces.
¿Cómo creció el número de iteraciones para llegar a la aproximación de la raíz?
a) El número de iteraciones creció también alrededor de un millón.
b) El número de iteraciones no aumentó demasiado.
c) El número de iteraciones fue el mismo.
2.-Si se varía la tolerancia para la función anterior, ¿en cuántas iteraciones se encuentra
la raíz?
Bisección Newton-Raphson
2.3.-¿Con cuál de los dos métodos aumentaron más las iteraciones al disminuir la
tolerancia?
Raíz Iteraciones
Si el valor inicial es de 2: 1 6
Si el valor inicial es de 1000: 1 22
Si el valor inicial es de 1000000: 1 39
Si el valor inicial es de -10: -2 8
3.5. Si el valor inicial es de 0.1: 0.49999 5
f(x) = Cos(x) – x2
Anotar el número de iteraciones y la raíz encontrada:
Newton- 8 0.824132 7
raphson
5.-Si se varía la tolerancia para la función anterior, ¿en cuántas iteraciones se encuentra
la raíz?
6.- sea la función =cos(x)-x^2. Usando bisección y tolerancia 0.0001, ¿en cuántas
iteraciones se encuentra la raíz?
Intervalo inicial raíz N° de iteraciones
[-0.5;1] 0.28412719 13
[0;1] 0.82415771 13
[-1000;1000] -0.82415342 24
En matlab
function pb_grafica2_Callback(hObject, eventdata, handles)
axes(handles.axes1);
x=str2double(get(handles.edit10,'String'));
fx=get(handles.edit1h,'String');
hold off
ezplot (fx);
hold on
grid on
zoom on
plot (x,subs(fx,x),'or');
funcion=get(handles.edit1h,'string');
x0=str2double(get(handles.edit2vi,'string'));
Tol=str2double(get(handles.edit3tol,'string'));
syms x
iteracion=0;
errorCalculado=100;
f=sym(funcion);
derivada=diff(f,x);
set(handles.uitable2,'data',{})
if derivada==0
hold off
cla
set(handles.uitable2,'data',{})
else
while errorCalculado>Tol
fx=subs(f,x0);
dx=subs(derivada,x0);
x1=x0-(fx/dx);
errorCalculado=abs(((x1-x0)/x1)*100);
%mostrar datos en tabla
x0=x1;
iteracion=iteracion+1;
end
end
catch
syms x
def=get(handles.edit1h,'string');
f=inline(def);
x0=str2double(get(handles.xl,'string'));
x1=str2double(get(handles.xu,'string'));
tol=str2double(get(handles.tol2,'string'));
n=0;
if f(x0)*f(x1)<0
x=x0;
while abs(f(x))>tol
x=(x0+x1)/2;
n=n+1;
if f(x0)*f(x)<0
x1=x;
else
x0=x;
end
end
set(handles.edit11,'string',n);
set(handles.edit10,'string',x);
set(handles.edit12,'String',tol);
end
syms x
cf=get(handles.edit1h,'string');
f=inline (cf);
x1=str2double(get(handles.valor3,'String'));
tol=str2double(get(handles.tol3,'String'));
n=0; error=100; d=0.01;
while(error>tol)
n=n+1;
x = x1 - d*x1*f(x1)/(f(x1 + d*x1)-f(x1));
error=abs(((x-x1)/x)*100);
x1 = x;
end
set(handles.ra3,'String',x);
set(handles.iter3,'String',n);
set(handles.er3,'String',tol);
x0=x1;
iteracion=iteracion+1;
end
end
catch
% msgbox('Un error ha ocurrido. Verifique que ha introducido todos
los datos y de la forma adecuada','Error','error')
end
syms x
funcion=get(handles.edit1h,'string');
f=inline(funcion);
x=-5:0.1:5;
n=length(x);
for i=1:n
y(i)=f(x(i));
end
j=-5;
for i=1:11
text(j,0,num2str(j));
j=j+1;
end
a=str2double(get(handles.xl,'string'));
b=str2double(get(handles.xu,'string'));
iteraciones=1;
j=1;
pmviejo=0;
while iteraciones<8
pm=((a+b)/2);
fa=f(a);
fb=f(b);
fpm=f(pm);
aa(j)=a;
bb(j)=b;
ppm(j)=pm;
ffa(j)=fa;
ffb(j)=fb;
ffpm(j)=fpm;
errorf=abs((pm-pmviejo)/pm);
err(j)=errorf;
if fa*fpm<0
b=pm;
end
if fa*fpm>0
a=pm;
end
pmviejo=pm;
j=j+1;
iteraciones=iteraciones+1;
end
set(handles.uitable1,'data',[aa' bb' ppm' ffa' ffb' ffpm' err']);
f=get(handles.edit1h,'string');
x0=str2double(get(handles.vi3,'string'));
x1=str2double(get(handles.valor3,'string'));
tol=str2double(get(handles.tol3,'string'));
syms x;
ea(1)=100;
set(handles.uitable3,'data',{})
hold off
cla
set(handles.uitable3,'Data',{})
%set(handles.respuesta,'string','no hay raiz');
i=1;
while abs(ea)>tol;
x=x0;
g=eval(f);
x=x1;
gg=eval(f);
xi=x1-((gg*(x0-x1))/(g-gg));
ea=abs((xi-x1)/xi)*100;
x0=x1;
x1=xi;
%mostrara datos en tabla
newRow ={i,x xi,ea};
oldData = get(handles.uitable3,'data');
newData=[oldData; newRow];
set(handles.uitable3,'data',newData)
i=i+1;
end
axes(handles.axes1);
x=str2double(get(handles.edit10,'String'));
fx=get(handles.edit1h,'String');
hold off
ezplot (fx);
hold on
grid on
zoom on
plot (x,subs(fx,x),'or');
axes(handles.axes3);
x=str2double(get(handles.ra3,'String'));
fx=get(handles.edit1h,'String');
hold off
ezplot (fx);
hold on
grid on
zoom on
plot (x,subs(fx,x),'or');