[LUG.ro] Te mando algunos programas

Alejandro Diaz Caro lugro@lugro.org.ar
Mon, 8 Dec 2003 19:19:15 -0300


--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Ac=E1 te mando los scrips que hice de Scilab... no me acuerdo=20
cuales te mand=E9 ya, pero te mando algunos. Son de este a=F1o.
Espero te sirvan.
Salu2
JANUS
P/D: el formato es P.E.[p].sce donde P=3Dpr=E1ctica, E=3Dejercicio,=20
p=3Dpunto
=2D-=20
El computador naci=F3 para resolver problemas que antes no=20
exist=EDan.
		-- Www.frases.com.=20

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="1.4.iii.sce"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="1.4.iii.sce"

Ly8gUHLhY3RpY2EgMSAtIEVqZXJjaWNpbyA0aWlpDQoNCg0KZnVuY3Rpb24gW25dPWVwc2lsb24N
Cg0KYyA9IDE7DQp3aGlsZSAoMStjKSA+IDENCgluPWM7DQoJYyA9IGMvMjsNCmVuZA0K

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="1.4.ii.sce"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="1.4.ii.sce"

Ly8gUHLhY3RpY2EgMSAtIEVqZXJjaWNpbyA0aWkNCg0KZnVuY3Rpb24gW25dPW1heHBvcw0KDQpj
PTE7DQp3aGlsZSAxL2MNCgluPWM7DQoJYz1jKjI7DQplbmQNCg==

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="1.4.i.sce"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="1.4.i.sce"

Ly8gUHLhY3RpY2EgMSAtIEVqZXJjaWNpbyA0aQ0KDQpmdW5jdGlvbiBbbl09cG9zDQoNCmM9MTsN
CndoaWxlIGMNCgluPWM7DQoJYz1jLzI7DQplbmQNCg==

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="2.17.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="2.17.sce"

// Ejercicio 17 - Pr=E1ctica 2

// X es el vector vertical inicial
function [X]=3Dnewt(X)

function J=3DJinv(Y)
	J=3D[2*Y(1,1)+Y(2,1)^3 3*Y(1,1)*Y(2,1)^2; 6*Y(1,1)*Y(2,1) 3*Y(1,1)^2-3*Y(2=
,1)^2];
  J=3Dinv(J);
endfunction

function FX=3DF(Y)
	FX=3D[Y(1,1)^2+Y(1,1)*Y(2,1)^3-9; 3*Y(1,1)^2*Y(2,1)-4-Y(2,1)^3];
endfunction

K=3DF(X)
Tolerancia=3D10E-9;
while abs(K(1,1))>Tolerancia & abs(K(2,1))>Tolerancia
	X=3DX-Jinv(X)*F(X);
	K=3DF(X);
end


--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="2.10.b.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="2.10.b.sce"

// Ejercicio 10b - Pr=E1ctica 2

function x=3Dnewt

x=3D0.5;
while abs(-log(x)-x)>10^(-9)
	x=3Dx-(-log(x)-x)/(-1/x-1);
end

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="2.14.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="2.14.sce"

// Pr=E1ctica 2 - Ejercicio 14

// (a,b) es el intervalo donde comenzar con el m=E9todo de bisecci=F3n
function r=3Draiz(a,b)

// Definici=F3n de la funci=F3n que estamos trabajando
// Para esta funci=F3n las ra=EDces est=E1n en 0 y m=E1s o menos en 1.934, =
as=ED que usar un intervalo
// apropiado
function y=3Df(x)
y=3Dx^2/4-sin(x);
endfunction

if ~f(a)
   r=3Da;
elseif ~f(b)
   r=3Db;
elseif f(a)*f(b)>0
   disp ("Error en el intervalo elegido, f(a)*f(b) debe ser <=3D 0")
	 r=3D0;   =20
else
		// Bisecci=F3n hasta una tolerancia de 10E-3
		tolerancia=3D10E-3
    r=3D(a+b)/2;
    while abs(f(r))>tolerancia
        if f(r)*f(a)<0
            b=3Dr;
        else
            a=3Dr;
        end
        r=3D(a+b)/2;
     end
     // Secante
		 while a~=3Db
		 		r=3Da-f(a)*(a-b)/(f(a)-f(b));
		 		a=3Db;
		 		b=3Dr;
		 end
end



--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="2.10.a.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="2.10.a.sce"

// Ejercicio 10a - Pr=E1ctica 2

function x=3Dpunto_fijo

x=3D0.5;
while abs(-log(x)-x)>10^(-9)
	x=3Dexp(-x);
end

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="2.9.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="2.9.sce"

// Ejercicio 9 - Pr=E1ctica 2

function [rs,rn,e]=3Draiz

// rs: Ra=EDz calculada por el m=E9todo de la Secante
// rn: Ra=EDz calculada por el m=E9todo de Newton
// e: Diferencia entre ambas
// x0: Valor inicial

// M=E9todo de la Secante
x0=3D1;
x1=3D2;
rs=3Dx1;
while tan(rs)-0.5*rs
	rs=3Dx1-(tan(x1)-0.5*x1)*((x1-x0)/((tan(x1)-0.5*x1)-(tan(x0)-0.5*x0)));
	x0=3Dx1;
	x1=3Drs;
end
// M=E9todo de Newton
rn=3D1;
while tan(rn)-0.5*rn
	rn=3Drn-(tan(rn)-0.5*rn)/(0.5+tan(rn)^2);
end
// Diferencia
e=3Dabs(rs-rn);

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="2.20.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="2.20.sce"

// Ejercicio 20 - Pr=E1ctica 2

function i=3Dveinte()

x=3D0.25;
i=3D1;
izq=3D(2^(i-1)*x^(2^(i-1)-1)-2^(i)*x^(2^(i)-1))/(1-x^(2^(i-1))+x^(2^(i)));
while abs(izq-((1+2*x)/(1+x+x^2)))>10E-6
	i=3Di+1;
	izq=3Dizq+(2^(i-1)*x^(2^(i-1)-1)-2^(i)*x^(2^(i)-1))/(1-x^(2^(i-1))+x^(2^(i=
)));
end


--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="3.1.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="3.1.sce"

// Pr=E1ctica 3 - Ejercicio 1
//   Sisntaxis: X =3D gauss(T)
//   Donde T es una matriz de n * n+1 ya que contiene al vector
//   de t=E9rminos independientes.


            ///////////////////////
            //  M=E9todo de Gauss  //
            ///////////////////////
           =20
function [X] =3D gauss(T)
           =20
M =3D T;
N =3D size(M);
n=3DN(1,1);
m=3DN(1,2);
if n~=3Dm-1
      disp('Error en las dimensiones de la matriz (debe ser de n x n+1)')
else
    for k=3D1:n-1
        j=3Dk+1;
        if M(k,k)=3D=3D0
            while j<=3Dn & M(j,k)=3D=3D0
                j=3Dj+1;
            end
            if j<=3Dn
                aux=3DM(j,:);
                M(j,:)=3DM(k,:);
                M(k,:)=3Daux;
            else
                j=3D0;
            end
        else
            if j
                for j=3Dk+1:N(1,1)
              	       M(j,:) =3D M(j,:)-(M(j,k)/M(k,k))*M(k,:);
                end
            end
        end
    end
    j=3D1;
    while j & j<=3Dn
        if ~M(j,j)
            j=3D0;
            disp ('Sistema con m=FAltiples soluciones o sin soluci=F3n')
        else
            j=3Dj+1;
        end
    end
    if j
      X=3Dzeros(n,1);    =20
     	j=3Dn;
        while j
            h=3D0;
            for k=3Dj:n
                h=3Dh+M(j,k)*X(k);
            end
            X(j)=3D(M(j,m)-h)/M(j,j);
            j=3Dj-1;
         end
      end
 end

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="4.3.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="4.3.sce"

// Pr=E1ctica 4 - Ejercicio 12

function X=3Dgc(A,b)

N=3Dsize(A);
n=3DN(1,1);
p=3Dzeros(n,1);
X=3Dzeros(n,1);
r=3Dzeros(n,1);
rant=3Dzeros(n,1);
k=3D0;

while r
	k=3Dk+1;
	if k=3D=3D1
		p(:,1)=3Dr(:,1);
	else
		B=3D(r'*r)/(rant'*rant);
		p=3Dr+B*p;
	end
	t=3D(r'*r)/(p'*A*p);
	X=3DX+t*p;
	rant=3Dr;



function p=3Dfact(k)
	p=3Dprod(1:k);
endfunction

H=3Dzeros(n,n);
Hi=3Dzeros(n,n);
for i=3D1:n
	for j=3D1:n
		H(i,j)=3D1/(i+j-1);
		Hi(i,j)=3D((-1)^(i+j)*fact(n+i-1)*fact(n+j-1))/((i+j-1)*(fact(i-1)*fact(j=
=2D1))^2*fact(n-i)*fact(n-j));
	end
end

// K(H) para norma 1

norma1H=3D0;
norma1Hi=3D0
for j=3D1:n
	sumH=3D0;
	sumHi=3D0;
	for i=3D1:n
		sumH=3DsumH+abs(H(i,j));
		sumHi=3DsumHi+abs(Hi(i,j));
	end
	if (sumH>norma1H)=20
		norma1H=3DsumH;
	end
	if (sumHi>norma1Hi)
		norma1Hi=3DsumHi;
	end
end
K1=3Dnorma1H*norma1Hi;

// K(H) para norma 2
// Tomo como valor aprox de norma 2 a:
// raiz del radio espectral de H*H' donde H' es H tranpuesta
// Pero, como H es sim=E9trica, H=3DH' (lo mismo con Hi)

autovaloresH=3Dspec(H*H);
autovaloresHi=3Dspec(Hi*Hi);
radespH=3D0;
radespHi=3D0;
for i=3D1:n
	if (abs(autovaloresH(i))>radespH)
		radespH=3Dabs(autovaloresH(i));
	end
	if (abs(autovaloresHi(i))>radespHi)
		radespHi=3Dabs(autovaloresHi(i));
	end
end
norma2H=3Dsqrt(radespH);
norma2Hi=3Dsqrt(radespHi);
K2=3Dnorma2H*norma2Hi;

// K(H) para norma infinito

norma_infH=3D0;
norma_infHi=3D0
for i=3D1:n
	sumH=3D0;
	sumHi=3D0;
	for j=3D1:n
		sumH=3DsumH+abs(H(i,j));
		sumHi=3DsumHi+abs(Hi(i,j));
	end
	if (sumH>norma_infH)=20
		norma_infH=3DsumH;
	end
	if (sumHi>norma_infHi)
		norma_infHi=3DsumHi;
	end
end
Kinf=3Dnorma_infH*norma_infHi;


--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/plain;
  charset="us-ascii";
  name="4.12.sce"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="4.12.sce"

Ly8gUHLhY3RpY2EgNCAtIEVqZXJjaWNpbyAxMg0KDQpmdW5jdGlvbiBYPWdjKEEsYikNCg0KTj1z
aXplKEEpOw0Kbj1OKDEsMSk7DQpYPXplcm9zKG4sMSk7DQpwPXplcm9zKG4sMSk7DQpyPWI7DQpy
YW50PXI7DQprPTA7DQoNCndoaWxlIHINCglrPWsrMTsNCglpZiBrPT0xDQoJCXA9cjsNCgllbHNl
DQoJCUI9cicqci8ocmFudCcqcmFudCk7DQoJCXA9citCKnA7DQoJZW5kDQoJdD1yJypyLyhwJypB
KnApOw0KCVg9WCt0KnA7DQoJcmFudD1yOw0KCXI9ci10KkEqcDsNCmVuZA0K

--Boundary-00=_jjP1/iEKVnMDijn
Content-Type: text/x-c++src;
  charset="us-ascii";
  name="6.3.sce"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="6.3.sce"

// A =3D [x1 y1;x2 y2; ... ;xn yn]
// x =3D valor a inter o extra polar

function y=3DLagrange(A,x)

N=3Dsize(A);
n=3DN(1,1);
ma=3DA(1,1);
mi=3DA(1,1);
for k=3D2:n
	if (A(k,1)>ma)
		ma=3DA(k,1);
	end
	if (A(k,1)<mi)
		mi=3DA(k,1);
	end
end
if (x>ma | x<mi)
	disp("Esta es una extrapolaci=F3n")
end
y=3D0;
for k=3D1:n
	produ=3D1;
	for i=3D1:n
		if(i~=3Dk)
			produ=3Dprodu*(x-A(i,1))/(A(k,1)-A(i,1));
		end
	end
	y=3Dy+produ*A(k,2);
end

--Boundary-00=_jjP1/iEKVnMDijn--