Solve a second-order differential equation with an array parameter that does not depend explicitly on the independent variable
Mostrar comentarios más antiguos
Hello everyone, I am trying to solve a second-order differential equation, which includes a parameter whose value for each step of the independent variable was extracted previously through simulations. In my code, that variable is called Delta, which have the same length that the time variable, which is the aforementioned independent variable, which is given also by the simulation step. The function where I have defined my second-order differential equation is the following:
function dxdt = odeFun(t, x, Delta)
mu0=4*pi*10^(-7);
alpha=0.001;
gamma=2.21*10^5;
kB=1.38064852*10^(-23);
a0=3.328*10^(-10);
muB=9.27400994*10^(-24);
mu=4*muB;
c=8.539*10^(-10);
V=c*(a0^2);
Ms=mu/V;
Ss=5/2;
jinter=532*kB;
Jinter=jinter*Ss^2/V;
C1=(2*alpha*gamma*Jinter)/(mu0*Ms);
C2=(2*(gamma^2)*Jinter)/(mu0*Ms);
Hcrit=0;
ramping_time=35e-12;
HSO=10*(10^4/12.54);
if t < ramping_time
y = max(HSO/ramping_time*t - Hcrit, 0);
elseif t < 45e-12
y = HSO-Hcrit;
else
y = 0;
end
dxdt(1) = x(2);
dxdt(2) = -C1*x(2)+C2*Delta*y;
dxdt = dxdt(:);
end
As you can see, Delta appears in the definition of dxdt(2). On the other hand, the code which calls this odeFun function is the following:
data=load('data.dat');
ic = [0; 0];
time=data(:,1); % s
Delta=data(:,2).*(10^(-9)); % m
[~,sol] = ode45(@(t,x) odeFun(t,x,Delta),time,ic);
This does not work. It only works if the following lines the definition of the function are rewritten:
function dxdt = odeFun(t, x, Delta, time)
dxdt(2)=-C1*x(2)+C2*interp1(time(:),Delta(:),t)*y;
I do not know if this do exactly what I want. I mean, in principle I do not need to interpolate nothing, because each value of Delta corresponds to each value of the time array. Does this do what I want or there is other way?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!