martes, 29 de mayo de 2012

Octave

Es una herramienta que es parecida a MATLAB, pero es gratis!. Con ella puedes realizar calculos, trabajar con matrices, plotear graficas, entre muchas otras cosas.

Tambien puedes hacer programas con las funciones usuales como: if, while, do entre otras. Puedes salvar tu trabajo realizado o esribir tus instrucciones en un archivo con extension .m, igual que en MATLAB, lo cual los hace compatibles.

Te presento dos ejemplos:

Ejemplo 1.


clear all;
verbose = 1;
mu1 = 4;
mu0 = 1;
N = 2000;
x0 = 0.8;
axis([1 4 0 1])
xlabel "r";
% ylabel "Equilibrium Point, x*";
for i = (1 : N + 1)
  mu = mu0 + (i - 1) * (mu1 - mu0) / N;
  clear x;
  x(1) = x0;
  j = 2;
  notconverged = 1;
  while (notconverged)
    x(j) = mu * x(j - 1) * (1 - x(j - 1));
    j++;
    for k = (1 : j - 2)
      if (abs(x(k) - x(j-1)) < 0.0001)
kstar = k;
notconverged = 0;
break;
      endif
    endfor
  endwhile
  clear muon;
  clear xstar;
  muon = 1;
  xstar = 0;
  for n = (kstar : j - 2)
    muon = [muon ; mu];
    xstar = [xstar ; x(n)];
  endfor
  M = [muon xstar];
  hold on
  gplot M title "" with dots 0
  if (verbose)
    if ((j - 1 - kstar) == 3)
      ans = input("Ready? Enter 1 to continue to the end ...\n");
      if (ans == 1) verbose = 0; endif
    endif
  endif
endfor
%title ("BIFURCATION PLOT FOR THE LOGISTIC MAP (1 < r < 4)")
refresh;
hold off;

* Si escribes estas instrucciones, graficaras una bifurcacion, que se vera como estas:


Ejemplo 2.

% This instructions solve the discrete Larva-Pupa-Adult model of flour beetles.

b=11.677;
Ul=0.5129;
Cea=0.011;
Cel=0.0093;
Cpa=0.0178;
Ua=0.11; %input('input adult mortality Ua:    ')
L0=70;  %input('input initial population L0:     ')
P0=30;
A0=65;
n=40;  %input('end of time interval b:     ')
L=zeros(n+1,1);
P=zeros(n+1,1);
A=zeros(n+1,1);
t=zeros(n+1,1);
L(1)=L0;
P(1)=P0;
A(1)=A0;
for i=1:n
t(i)=i-1;
L(i+1)=b*A(i)*exp(-Cea*A(i)-Cel*L(i));
P(i+1)=L(i)*(1-Ul);
A(i+1)=P(i)*exp(-Cpa*A(i))+A(i)*(1-Ua);
end
t(n+1)=n;
plot(t,L,'-o',t,P,'r:.',t,A,'-*')
legend('Larvae','Pupae','Adults',0)

Y con estas instrucciones veras el crecimeinto de una poblacion adulta de abejas.
Referencias:


No hay comentarios:

Publicar un comentario