I am trying to solve this complex ODE with ode45 and no matter which solver I use I get a similar error from each solver (using odepkg 0.8.5). I've used octave online to solve the very same ode as well as matlab, but I need to be able to solve it using my octave version 4.0.3.
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 %The Delta functions simply return values 0 or 1 depending on t, T and N are defined inputs %Hamil(X) returns a 3x3 Hamiltonian matrix which means y is a 3x1 vector Command: >> 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(t,y,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 error: ode45: A(I,J,...) = X: dimensions mismatch error: called from ode45 at line 345 column 17 I'm not sure why I'm only getting this error on my downloaded version of Octave. Please help. Thank you, Dalton _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
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. |
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 <[hidden email]> wrote: Dalton Jones wrote _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
The error before was about dimensions. Now the error is different: Something is wrong in your Hamil function ("index out of bounds"). You did not show this function, so again, I cannot help. Sebastian |
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 |
In reply to this post by Sebastian Schöps
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) _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Yeah I'm using octave 4.0.3, I couldn't find anywhere to download anything newer for the Mac. Could you direct me somewhere to download the latest version? Thanks, Dalton On Tue, Aug 29, 2017 at 2:37 PM, Sebastian Schöps [via Octave] <[hidden email]> wrote: Hi, |
daltonj283 wrote
> Yeah I'm using octave 4.0.3, I couldn't find anywhere to download anything > newer for the Mac. Could you direct me somewhere to download the latest > version? Recent octave versions contain ode45 natively, i.e. you do not need odepkg anymore. You can get it either 1. from homebrew, see https://wiki.octave.org/Octave_for_macOS#Homebrew In short "brew install octave" will install the most recent stable version (version 4.2.1) and "brew install octave --HEAD" will compile the current version from the development sources, i.e. version "4.3.0+"). 2. Binary I recently prepared a binary version of 4.2.1 (based on homebrew). I have send it to a few colleagues for testing but there might still be bugs (however, I am rather confident that it is fine). You can get it here: https://www.dropbox.com/s/7o6w67vfnka1in2/octave_cli_421_appleblas.dmg?dl=0 For verification, the shasum is 4cfa0f4f0136b5a0c4c5c88e30f746e8bc4508c7. Seb. -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
This post has NOT been accepted by the mailing list yet.
So I tried installing Octave using brew install octave, and it worked but I was unable to open Octave with the GUI. It would only allow me to use the command line of Octave. So then I tried brew install octave --HEAD and that resulted in the same problem. I even tried the command octave --force-gui On Wed, Aug 30, 2017 at 4:46 AM, Sebastian Schöps [via Octave] <[hidden email]> wrote: daltonj283 wrote |
daltonj283 wrote
> So I tried installing Octave using *brew install octave*, and it worked > but > I was unable to open Octave with the GUI. It would only allow me to use > the > command line of Octave. So then I tried *brew install octave --HEAD *and > that resulted in the same problem. I even tried the command octave > --force-gui True. Since homebrew moved to qt 5.9 (which is justified as older version have significant security issues are unmaintained) we do not build octave with the GUI anymore. Sorry, it's too buggy to be shipped. Sadly, I have not the skills to fix the qt issues and the people that might have the skills do not care about macOS :( For now, you either live with an outdated octave (using an outdated qt) or a recent octave without GUI.... or you are a qt expert and you can help me fixing it :) Personal note: the command line interface is not so bad after all. I would always go for option 2. Sebastian -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
This post has NOT been accepted by the mailing list yet.
Ok, yeah it was pretty easy to learn how to use it on the command line. I've gotten most of my scripts running on it now, save for the one I made another post about. Haha I don't think I can help you there, but thanks for all your help, I really appreciate it! Dalton On Wed, Aug 30, 2017 at 11:50 PM, Sebastian Schöps [via Octave] <[hidden email]> wrote: daltonj283 wrote |
In reply to this post by Sebastian Schöps
In MacPorts we still use the old qt (perhaps we should look into the security issues as well). However, I use Jupyter Notebooks with the octave kernel as my front end, and rarely load the octave GUI anymore. I have found that this is easier to display to a class when working problems.
Marius -- Marius Schamschula _______________________________________________ Help-octave mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/help-octave |
Free forum by Nabble | Edit this page |