# Metodos numericos en scilab

Solo disponible en BuenasTareas
• Páginas : 5 (1097 palabras )
• Descarga(s) : 0
• Publicado : 5 de enero de 2012

Vista previa del texto
Ejercicios de Métodos numéricos en scilab

1. MÉTODO DE BISECCIÓN

function y=f(h)
y=-12.4 + 10*(0.5*%pi*(1**2) -(1**2)*asin(h/1)-h*((1**2)-h**2)**0.5);
endfunction

function pn=biseccion(f, h0,h1,aprox)
i=1;
er(1)=100;
if f(h0)*f(h1) < 0
ha(1)=h0;
hb(1)=h1;
pn(1)=(ha(1)+hb(1))/2;
printf('Ite.\t\t ha\t\t hb\t\t pn\t\t f(pn)\t Error \n');
printf('%2d \t%11.7f \t %11.7f \t %11.7f \t %11.7f \n',i,ha(i),hb(i),pn(i),f(pn(i)));
while abs(er(i)) >= aprox
if f(ha(i))*f(pn(i))< 0
ha(i+1)=ha(i);
hb(i+1)=pn(i);
end
if f(ha(i))*f(pn(i))> 0
ha(i+1)=pn(i);
hb(i+1)=hb(i);
end
pn(i+1)=(ha(i+1)+hb(i+1))/2;
er(i+1)=abs((pn(i+1)-pn(i))/(pn(i+1)));
printf('%2d\t %11.7f \t %11.7f \t %11.7f \t %11.7f \t %7.6f \n',i+1,ha(i+1),hb(i+1),pn(i+1),f(pn(i+1)),er(i+1));
i=i+1;
end
else
printf('En el intervalo escogido, no existe una raiz');
end
endfunction

2. MÉTODO DE NEWTON-RAPHSON

function y=f(x)
y=2*(x**3) + x- 1;
endfunction

function y=df(x)
y=6*x**2 + 1;
endfunction

function pn=newtonraphson(f, p0,aprox );
i=1;
er(1)=1;pn(1)=p0;
while abs(er(i))>=aprox;
pn(i+1)=pn(i)-f(pn(i))/df(pn(i));
er(i+1)=abs((pn(i+1)-pn(i))/pn(i+1));
i=i+1;
end
printf(' i \t pn(i) Error aprox (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %7.6f \n',j-1,pn(j),er(j));
end
endfunction

3. ITERACIÓN DE PUNTO FIJO

function y=f(t)
y=300-80.425*t+201.0625*(1-2.718281828**(-(0.1)*t/0.25));endfunction

function pn = puntofijo(f, p0,aprox)
i=1;
er(1)=1;
pn(1)=p0;
while abs(er(i))>=aprox;
pn(i+1) = f(pn(i));
er(i+1) = abs((pn(i+1)-pn(i))/pn(i+1));
i=i+1;
end
printf(' i \t pn(i) Error aprox (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %7.7f \n',j-1,pn(j),er(j));
end
endfunction

4.

a- EL MÉTODO DE NEWTON P0 = 1

function y=f(x)y=4*cos(x)-2.718281828**(x);
endfunction

function y=df(x)
y=-4*sin(x)-2.718281828**(x);
endfunction

function pn=newtonraphson(p0,aprox);
i=1;
er(1)=1;
pn(1)=p0;
while abs(er(i))>=aprox;
pn(i+1)=pn(i)-f(pn(i))/df(pn(i));
er(i+1)=abs((pn(i+1)-pn(i))/pn(i+1));
i=i+1;
end
printf(' i \t Pn(i) Error aprox (i) \n');
for j=1:i;
printf('%2d \t %11.7f \t %7.15f\n',j-1,pn(j),er(j));
end
endfunction

b) EL MÉTODO DE LA SECANTE

function y=g(x)
y=4*cos(x)-2.718281828**(x);
endfunction

function pn = secante(x0,x1,aprox)
j=2;
i=1;
pn(1)=x0;
pn(2)=x1;
er(i)=1;
while abs(er(i))>=aprox
pn(j+1)=(pn(j-1)*f(pn(j))-pn(j)*f(pn(j-1)))/(f(pn(j))-f(pn(j-1)));
er(i+1)=abs((pn(j+1)-pn(j))/pn(j+1));
j=j+1;
i=i+1;
end

printf(' i \t\tpn(i) \t\t Error aprox (i) \n');
printf('%2d \t %11.7f \t\t \n',0,pn(1));

for k=2:j;
printf('%2d \t %11.7f \t %7.8f \n',k,pn(k),er(k-1));
end

endfunction

5.
a- Aplique el método de la secante

function y=f(x)
y=x**2-6;
endfunction

function pn = secante(f, p0,p1,aprox)
j=2;
i=1;
pn(1)=p0;
pn(2)=p1;
er(i)=1;
while abs(er(i))>=aproxpn(j+1)=(pn(j-1)*f(pn(j))-pn(j)*f(pn(j-1)))/(f(pn(j))-f(pn(j-1)));
er(i+1)=abs((pn(j+1)-pn(j))/pn(j+1));
j=j+1;
i=i+1;
end

printf(' i \t\t pn(i) \t Error aprox (i) \n');
printf('%2d \t %11.7f \t \n',0,pn(1));

for k=2:j;
printf('%2d \t %11.7f \t %7.7f \n',k-1,pn(k),er(k-1));
end

endfunction

b- Aplique el método de la falsa posición

function y=f(x)
y= (x^2) - 6;
endfunctionfunction xn=falsaposicion(f, a1,b1,max1)
i=1;
ea(1)=100;

// xn vector que almacena la {xn} completa