help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: samin syntax error


From: Dalton Jones
Subject: Re: samin syntax error
Date: Thu, 31 Aug 2017 14:14:26 -0700

Ok I understand where that was coming from, I was using Text Editor to edit my scripts and it gave me those fancy quotation marks. Octave is now running my global minimization script but it's taking a very long time and hasn't printed out any "temperatures." It may be because of the use of the unique function in Bangcost. When I was using Matlab I had to use their uniquetol function because Matlab was reading numbers with a lot of decimals as different when they were really the same, and then trying to solve my ode over a time interval of 0, eventually erroring out after hours of trying to solve it. Here are the functions I'm using for this:

function Er=Bangcost(T)
  tf=.75;
  N=[1 1 1 1 2 2];
  Y0=[1; 0; 0];
  Ts=[T; tf];
  Tsu=unique(Ts);
  Tsu(Tsu==0)=[];
  n=1;
  a=0;
  while (n <= length(Tsu))
    [Ti,Y]=ode45(@(t,y)bangodefun(t,y,T,N),[a Tsu(n)],Y0);
    S=length(Ti);
    Y0=Y(S,:).';
    a=Tsu(n);
    n++;
  endwhile
  YT=(1/sqrt(3))*[1; 1; 1];
  Er=1-((Y0.'*YT)*(Y0.'*YT)');
endfunction

function dydt=bangodefun(t,y,T,N)
  X=[Delta1(t,T(1:N(1))); Delta2(t,T(N(1)+1:sum(N(1:2)))); Delta3(t,T(sum(N(1:2))+1:sum(N(1:3)))); Delta4(t,T(sum(N(1:3))+1:sum(N(1:4)))); Delta5(t,T(sum(N(1:4))+1:sum(N(1:5)))); Delta6(t,T(sum(N(1:5))+1:sum(N(1:6))))];
  H=Hamil(X);
  dydt=-i*H*y;
endfunction

function [ H ] = Hamil( X )
  H=[X(1)+X(2)-X(3) -2*X(5) -2*X(6); -2*X(5) X(1)-X(2)+X(3) -2*X(4); -2*X(6) -2*X(4) X(2)-X(1)+X(3)];
endfunction

function [B1]=Delta1(t,tB1)
  n1=length(tB1);
  tsB1=sort(tB1);
  n=1;
  while n<=n1
    if t<=tsB1(n)
        B1=(1+(-1)^(n))/2;
        n=n1+1;
    elseif t>tsB1(n1)
        B1=mod(n1,2);
        n=n1+1;
    else
        n=n+1;
    end
  end
end

function [B2]=Delta2(t,tB2)
  n2=length(tB2);
  tsB2=sort(tB2);
  n=1;
  while n<=n2
    if t<=tsB2(n)
        B2=(1+(-1)^(n))/2;
        n=n2+1;
    elseif t>tsB2(n2)
        B2=mod(n2,2);
        n=n2+1;
    else
        n=n+1;
    end
  end
end

function [B3]=Delta3(t,tB3)
  n3=length(tB3);
  tsB3=sort(tB3);
  n=1;
  while n<=n3
    if t<=tsB3(n)
        B3=(1+(-1)^(n))/2;
        n=n3+1;
    elseif t>tsB3(n3)
        B3=mod(n3,2);
        n=n3+1;
    else
        n=n+1;
    end
  end
end

function [J1]=Delta4(t,tJ1)
  n4=length(tJ1);
  tsJ1=sort(tJ1);
  n=1;
  while n<=n4
    if t<=tsJ1(n)
        J1=(1+(-1)^(n))/2;
        n=n4+1;
    elseif t>tsJ1(n4)
        J1=mod(n4,2);
        n=n4+1;
    else
        n=n+1;
    end
  end
end

function J2=Delta5(t,tJ2)
  n5=length(tJ2);
  tsJ2=sort(tJ2);
  n=1;
  while (n <= n5)
    if t<=tsJ2(n)
        J2=(1+(-1)^(n+1))/2;
        n=n5+1;
    elseif t>tsJ2(n5)
        J2=-1*(mod(n5,2)-1);
        n=n5+1;
    else
        n=n+1;
    endif
  endwhile
endfunction

function [J3]=Delta6(t,tJ3)
  n6=length(tJ3);
  tsJ3=sort(tJ3);
  n=1;
  while n<=n6
    if t<=tsJ3(n)
        J3=(1+(-1)^(n+1))/2;
        n=n6+1;
    elseif t>tsJ3(n6)
        J3=-1*(mod(n6,2)-1);
        n=n6+1;
    else
        n=n+1;
    endif
  endwhile
endfunction





Thanks,
Dalton

reply via email to

[Prev in Thread] Current Thread [Next in Thread]