second order differential equation with variable coefficient

조회 수: 4 (최근 30일)
Francesco
Francesco 2012년 2월 1일
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개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by