- Introduce “z(t) = y'(t)” to represent the first derivative of y(t).
- Rewrite the second-order ODE as two first-order ODEs:
how to convert second order ODE to first in the below FDTD problem
5 次查看(过去 30 天)
显示 更早的评论
for index=1:iterationsNum
I am currently workin on this particlar FDTD problem where it is required to input the above second order ODE into the below code in the rohNew line.Thougt about using OdeToVectorfield but could not understand how to integrate it in this context.
You can just ignore the constants.
ELz=(EL(2:end)-EL(1:end-1))/dz;
ELnew(2:end)=EL(2:end)+dt*c/n*(1i*kappa*roh(2:end).*ES(2:end)-ELz);
ESz=(ES(2:end)-ES(1:end-1))/dz;
croh=conj(roh);
ESnew(1:end-1)=ES(1:end-1)+dt*c/n*(1i*kappa*croh(1:end-1).*EL(1:end-1)+ESz);
f = wgn(1,N,Q/dt/dz,'complex','linear');%f=sqrt(Q/dz)*(randn(1,N))/sqrt(dt);%sqrt(Q/dz)*(randn(1,N)+1i*randn(1,N))/sqrt(2)/sqrt(dt);
rohNew=roh+dt*(1i*LAMBDA*EL.*conj(ES)+f-GAMMAb*roh/2);
EL=ELnew;
ES=ESnew;
roh=rohNew;
end
0 个评论
回答(1 个)
UDAYA PEDDIRAJU
2024-1-15
Hi Yogesh,
1) To convert a second-order ODE to a first-order system, introduce a new variable for the derivative of the original variable. For the given ODE:
y'(t) = z(t)
z'(t) = f(t, y(t), z(t))
In your case, you can try introducing a new variable “roh'(t) = rohNew(t) - roh(t)” and rewrite the second-order ODE as a system of two first-order ODEs:
ELz=(EL(2:end)-EL(1:end-1))/dz;
ELnew(2:end)=EL(2:end)+dt*c/n*(1i*kappa*roh(2:end).*ES(2:end)-ELz);
ESz=(ES(2:end)-ES(1:end-1))/dz;
croh=conj(roh);
ESnew(1:end-1)=ES(1:end-1)+dt*c/n*(1i*kappa*croh(1:end-1).*EL(1:end-1)+ESz);
f = wgn(1,N,Q/dt/dz,'complex','linear');%f=sqrt(Q/dz)*(randn(1,N))/sqrt(dt);%sqrt(Q/dz)*(randn(1,N)+1i*randn(1,N))/sqrt(2)/sqrt(dt);
rohNew=roh+dt*(1i*LAMBDA*EL.*conj(ES)+f-GAMMAb*roh/2);
rohPrime = rohNew - roh;
EL=ELnew;
ES=ESnew;
roh=rohNew;
2) Regarding the usage of “ odeToVectorField” yes, it is useful to convert the higher order ODEs to a system of first-order ODEs, here is an example.
syms y(t) z(t)
Dy = diff(y, t);
Dz = diff(z, t);
ode = Dz == f(t, y, z); % Replace f(t, y, z) with your specific function
V = odeToVectorField(ode);
M = matlabFunction(V, 'vars', {'t', 'Y'});
I hope this gives you an idea on how to convert 2nd order ODE to 1st order system!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!