[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ode45 error: dimension mismatch in line 345 column 17
From: |
Sebastian Schöps |
Subject: |
Re: ode45 error: dimension mismatch in line 345 column 17 |
Date: |
Tue, 29 Aug 2017 23:36:41 +0200 |
Hi,
please keep the mailing list in cc.
> No the Hamil function returns a 3x3 matrix based on the values of X, and it
> along with every other function works fine in the command line. It seems that
> for some reason the Delta functions are not returning values when called in
> ode45, making X=[ ].
>
> 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
>
> Dalton
I tried your functions and they work for me using
"[t,Y]=ode45(@(t,y)bangodefun(y,t,T,N), [0 1], Y0)". I am using them with
octave 4.3.0+ on macOS. Maybe you have several incompatible versions in your
path?
Sebastian
---------------------------------------
Just paste this into the octave window ...
---------------------------------------
function dydt=bangodefun(y,t,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 [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
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
T=[0; 0; 0; 0; .28; .56; .28; .56];
N=[1 1 1 1 2 2];
Y0=[1; 0; 0];
[t,Y]=ode45(@(t,y)bangodefun(y,t,T,N), [0 1], Y0)
- ode45 error: dimension mismatch in line 345 column 17, Dalton Jones, 2017/08/27
- Re: ode45 error: dimension mismatch in line 345 column 17, Sebastian Schöps, 2017/08/28
- Re: ode45 error: dimension mismatch in line 345 column 17, Dalton Jones, 2017/08/29
- Re: ode45 error: dimension mismatch in line 345 column 17, Sebastian Schöps, 2017/08/29
- Re: ode45 error: dimension mismatch in line 345 column 17, daltonj283, 2017/08/29
- Message not available
- Re: ode45 error: dimension mismatch in line 345 column 17,
Sebastian Schöps <=
- Re: ode45 error: dimension mismatch in line 345 column 17, daltonj283, 2017/08/29
- Re: ode45 error: dimension mismatch in line 345 column 17, Sebastian Schöps, 2017/08/30
- Message not available
- Re: ode45 error: dimension mismatch in line 345 column 17, Sebastian Schöps, 2017/08/31
- Re: ode45 error: dimension mismatch in line 345 column 17, Marius Schamschula, 2017/08/31