second order differential equation with variable coefficient
3 次查看(过去 30 天)
显示 更早的评论
Hi,
As wrote in a previous question I have to solve the equation: d^2x/dt^2= (q/m)(E/v^2)
I have wrote the following code:
q=1; m=1; v=1; E=1;
rhs=@(z,x)[x(2);(q/m)*(E/v^2)];
[za, xa] = ode45(rhs, [0 100], [0 0]);
and it works fine.
The problem is that E for me is a function of z that I can write as:
Ez=zeros(1,100);
for i=1:1:100
if (i<=10 || i>=50)
Ez(i)=0;
else
Ez(i)=1;
end
end
I have found an example here: http://www.mathworks.it/help/techdoc/ref/ode23.html where is shown how to solve ode with time-dependent terms, but is is about a first order problem and I'm not able to write something similar for my second order problem... could you help me?
0 个评论
回答(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!