Azzera filtri
Azzera filtri

ode45 gets stuck when making the function a column vector?

2 visualizzazioni (ultimi 30 giorni)
I am trying to solve a relatively simple ode. I am aware I could possibly use a different ode function but don't think that is the problem.
I get the very common error that my function must return a column vector, so then add the dx=zeros(2,1) line into my function.
When I do this however the programme doesn't complete - it starts but then seems to get stuck somehow, busy.
If I instead transpose my dx to get a column vector, the result is the same.
This is my function:
function dx = minibandvel(t,x)
F=1^(-20);
tau=10^(-5);%s
del=19.1*10^(-3);%eV
d=8.241*10^(-9);%m
hbar=10.5*10^(-34);
%dx=zeros(2,1);
dx(1)=((tau*del)/(2*hbar))*sin(x(2));
dx(2)=(F*d*tau)/hbar;
%dx=dx.';
end
used in this:
close all
clc
initialx(1)=0;
initialx(2)=0;
tspan=[0 0.1];
[t,x]= ode45 (@minibandvel,tspan,[initialx(1) initialx(2)]);
plot (t,x)
The odd thing is that I had run the programme several times successfully; and had this issue before but it could be solved by simply restarting MATLAB.
Thanks in advance

Risposta accettata

Star Strider
Star Strider il 17 Dic 2016
Looking at your constants:
tau=10^(-5);%s
del=19.1*10^(-3);%eV
d=8.241*10^(-9);%m
hbar=10.5*10^(-34);
The ode45 solver will get there, but it could take several hours. A better — and certainly faster — solution is a ‘stiff’ solver such as ode15s.
  2 Commenti
Physics
Physics il 3 Mar 2017
Thanks for your reply.
The solution I found was to define the fraction used and then input that into the ODEs.
For example, fraction=(F*d*tau)/hbar;
and then
dx(2)=fraction

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by