Implementación de Algoritmos Matemáticos en Maxima: Ejemplos Prácticos

Enviado por Chuletator online y clasificado en Matemáticas

Escrito el en español con un tamaño de 2,6 KB

1. Función Recurrente

Implementación de sucesiones definidas por recurrencia y cálculo de límites:

kill(W);
W[n] := if n=1 then 111 elseif n=2 then 3 elseif n=3 then 13 else W[n-1] + W[n-2] + W[n-3];
W[15];
makelist(W[n], n, 1, 15, 1);

Wi[n] := if n=1 then 111 elseif n=2 then 3 elseif n=3 then 13 else block(k1:111, k2:3, k3:13, for k from 4 thru n do (k4: k1 + k2 + k3, k1: k2, k2: k3, k3: k4), k4);
Wi[15];
makelist(Wi[n], n, 1, 15, 1);
Wi[100000]/Wi[99999], numer;

2. Manipulación de Listas (Quitaunos)

Función recursiva para eliminar elementos unitarios de una lista:

kill(all);
quitaunos(L) := if L[1] = 1 then delete(1, L) else quitaunos(L);
L:[1, 2, 0, 0, 3, 0, 1];
quitaunos(L);

3. Resolución de Sistemas (ALGSYS)

Resolución de sistemas de ecuaciones no lineales mediante métodos simbólicos y numéricos (Newton-Raphson):

kill(all);
faux(x,y,z) := [x^2/2 + 1/3, x + y + z/4, x^2 - y^2 + z^2/4];
f(V) := faux(V[1], V[2], V[3]);
f([x,y,z]);
ecus: f([x,y,z]) - [x,y,z];
algsys(ecus, [x,y,z]);
algsys(ecus, [x,y,z]), numer;

nor(V) := sqrt(V . V);
fpprec : 200;
solaproxpuntofijo : block( v0 : [0, 0, 0], while nor(f(v0) - v0) > 10^-14 do ( v0 : bfloat(f(v0)) ), v0 );

g(V) := f(V) - V;
define(jaco(x, y, z), jacobian(g([x, y, z]), [x, y, z]));
jacoV(V) := jaco(V[1], V[2], V[3]);
newton(V) := transpose(V - invert(jacoV(V)) . g(V))[1];
block( V : [0, 1, -1], while nor(g(V)) > 10^-14 do ( V : bfloat(newton(V)) ), V );

4. Distancia al Origen y Multiplicadores de Lagrange

Optimización restringida para encontrar la distancia mínima y máxima a un punto:

F1(x, y) := (x - 2)^2 + (y + 3)^2 - 4;
d2(x, y) := x^2 + y^2;
L(x, y, a) := d2(x, y) + a * F1(x, y);
Lx : diff(L(x, y, a), x); Ly : diff(L(x, y, a), y); La : diff(L(x, y, a), a);

sols1 : algsys([Lx, Ly, La], [x, y, a]), numer;
crit1 : sols1[1];
crit2 : sols1[2];
Dmin : ev(d2(x, y), crit1);
Dmax : ev(d2(x, y), crit2);

F2(x, y) := (x - 2)^2 + (y + 3)^2 - 6 + sin(x + y);
L2(x, y, a) := d2(x, y) + a * F2(x, y);
L2x : diff(L2(x, y, a), x); L2y : diff(L2(x, y, a), y); L2a : diff(L2(x, y, a), a);
define(LL2(x, y, a) := [L2x, L2y, L2a]);
LL3(V) := LL2(V[1], V[2], V[3]);
define(jaco(x, y, a), jacobian(LL3([x, y, a]), [x, y, a]));
jaco2(V) := jaco(V[1], V[2], V[3]);
newton(V) := transpose(V - invert(jaco2(V)) . LL3(V))[1];
nor(V) := sqrt(V . V);

res := block( v0 : [3, -5, -1], while nor(LL3(v0)) > 10^-15 do ( v0 : bfloat(newton(v0)) ), v0 );
resaprox : res, numer;
D2max : d2(resaprox[1], resaprox[2]);
DMAX : sqrt(D2max);

Entradas relacionadas: