Está en la página 1de 2

function biseccion1

f1=input('ingrese la funcion ','s');


f=inline(f1);
a=input('ingrese el limite inferior a: ');
b=input('ingrese el limite superior b: ');
n=input('ingrese el numero de iteraciones n: ');
f=inline(f1)
for i=1:1:n
xr=(a+b)/2;
if f(a)*f(xr)<0;
b=xr
else f(xr)*f(b)<0;
a=xr

end
end
disp('La aproximacion de la raiz es ')
disp(xr)

function biseccion2
f1=input('ingrese la funcion ','s');
a=input('ingrese el limite inferior a: ');
b=input('ingrese el limite superior b: ');
es=input('ingrese el error tolerable : ');
f=inline(f1)
cont=1
ea=abs((b-a)/2)*100
while ea>es
cont=cont+1;
xr=(a+b)/2;
if f(a)*f(xr)<0;
b=xr
ea=abs((xr-a)/xr)*100
else f(xr)*f(b)<0;
a=xr
ea=abs((xr-b)/xr)*100
end
end
disp('numero de iteraciones ')
disp(cont)
disp('La aproximacion de la raiz es ')
disp(xr)
function gauss
A=input('ingrese la matriz A= ');
B=input('ingrese la columna B= ');
n=length(A);
AB=[A,B];
X=zeros(n,1);
for j=1:1:n;
if AB(j,j)==0
disp('reordenar la matriz');
end
AB(j,:)=(1/AB(j,j))*AB(j,:);
for i=[1:j-1,j+1:n];
m=-AB(i,j);
AB(i,:)=m*AB(j,:)+AB(i,:);
end
end
X=AB(:,n+1)
disp('la solucion es')
disp(X)

function raphsonmultiple
f=input('ingrese la funcion f(x)= ','s');
g=input('ingrese la funcion g(x)= ','s');
x1=input('ingrese el valor inicial x1= ');
y1=input('ingrese el valor inicial y1= ');
n=input('ingrese el numero de iteraciones n= ');
syms x y
dfx=diff(f,x);
dfy=diff(f,y);
dgx=diff(g,x);
dgy=diff(g,y);
for i=1:1:n
dfx1=subs(dfx,{x,y},{x1,y1});
dfy1=subs(dfy,{x,y},{x1,y1});
dgx1=subs(dgx,{x,y},{x1,y1});
dgy1=subs(dgy,{x,y},{x1,y1});
fp1=subs(f,{x,y},{x1,y1});
gp1=subs(g,{x,y},{x1,y1});
J=[dfx1,dfy1;dgx1,dgy1];
X1=[x1;y1];
F1=[fp1;gp1];
X=X1-inv(J)*F1
x1=X(1,1);
y1=X(2,1);
end
disp('la solucion es ' )
disp(X)

También podría gustarte