help-octave
[Top][All Lists]

## Re: ode45 error: dimension mismatch in line 345 column 17

 From: Dalton Jones Subject: Re: ode45 error: dimension mismatch in line 345 column 17 Date: Tue, 29 Aug 2017 13:29:41 -0700

That was actually just a typo when I wrote it on the website, I just checked to make sure I was calling ode45 with t and y in the correct order and got the same error message. The first time I posted my question, the Delta functions literally just returned values 1 or 0 independent of inputs. I did this because when I called ode45 with the time dependent Delta's it tells me that the return values are left unassigned even though I can call each Delta function from the command line and it works as expected. With all of my other functions (Hamil and bangodefun) the same here are my current Delta functions now that I have made them dependent on what time it is again and the current error message:

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

Commands:

>> T=[0; 0; 0; 0; .28; .56; .28; .56];
>> N=[1 1 1 1 2 2];
>> Y0=[1; 0; 0];
>>[t,y]=ode45(@(y,t)bangodefun(y,t,T,N),[0 1],Y0)
warning: Option "RelTol" not set, new value 0.000001 is used
warning: called from
ode45 at line 113 column 5
warning: Option "AbsTol" not set, new value 0.000001 is used
warning: Option "InitialStep" not set, new value 0.010000 is used
warning: Option "MaxStep" not set, new value 0.010000 is used
warning: Delta1: some elements in list of return values are undefined
warning: Delta2: some elements in list of return values are undefined
warning: Delta3: some elements in list of return values are undefined
warning: Delta4: some elements in list of return values are undefined
warning: Delta5: some elements in list of return values are undefined
warning: Delta6: some elements in list of return values are undefined
error: Hamil: A(I): index out of bounds; value 1 out of bound 0
error: called from
Hamil at line 2 column 4
bangodefun at line 3 column 4
ode45 at line 345 column 17

On Mon, Aug 28, 2017 at 12:57 AM, Sebastian Schöps wrote:
Dalton Jones wrote
> function dydt=bangodefun(y,t,T,N)
> ...
> endfunction
> ...
> [t,Y]=ode45(@(t,y)bangodefun(t,y,T,N), [0 1], Y0)

I cannot help debugging as you did not give us the Delta functions. However,
I guess your trouble is that you swapped the arguments t and y in the
definition of the anonymous function.

Seb.

--
View this message in context: http://octave.1599824.n4.nabble.com/ode45-error-dimension-mismatch-in-line-345-column-17-tp4684693p4684696.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list