help-octave
[Top][All Lists]
Advanced

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

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


From: daltonj283
Subject: Re: ode45 error: dimension mismatch in line 345 column 17
Date: Tue, 29 Aug 2017 14:50:04 -0700 (MST)

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] <
address@hidden> wrote:

> 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] <http:///user/SendEmail.jtp?type=node&node=4684717&i=0>
> https://lists.gnu.org/mailman/listinfo/help-octave
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://octave.1599824.n4.nabble.com/ode45-error-
> dimension-mismatch-in-line-345-column-17-tp4684693p4684717.html
> To unsubscribe from ode45 error: dimension mismatch in line 345 column 17, 
> click
> here
> <http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4684693&code=ZGFsdG9uajI4M0BnbWFpbC5jb218NDY4NDY5M3wtMjMyODg4MTU2>
> .
> NAML
> <http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




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



reply via email to

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