필터 지우기
필터 지우기

Integrate for a specific period of time

조회 수: 9 (최근 30일)
Allison Bushman
Allison Bushman 2019년 9월 12일
답변: Torsten 2019년 9월 13일
Please help me. I am trying to use Euler integration to integrate for 10 seconds with a step size of .01 seconds. Plot x versus time.
x(0) = 1
t=0:.01:10;
x0=1;
xdot=-2*(x^3)+sin(0.5*t)*x;
for t=0:0.01:10
x=integrate(xdot,t,x0);
end
plot(t,x)
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 9월 13일
However you do not have a differential equation, so it is not obvious to me what Euler integration would have to do with the situation.
Allison Bushman
Allison Bushman 2019년 9월 13일
xdot is dx/dt

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2019년 9월 13일
t=0:.01:10;
x = zeros(numel(t));
x(1) = 1;
fun_xdot = @(t,x) -2*(x^3) + sin(0.5*t)*x;
for i = 1:numel(t)-1
x(i+1) = x(i) + (t(i+1)-t(i))*fun_xdot(t(i),x(i));
end
plot(t,x)

추가 답변 (1개)

Robert U
Robert U 2019년 9월 13일
편집: Robert U 2019년 9월 13일
Hi Allison,
you can use one of Matlab's integrated ODE solvers to solve your differential equation. The code below makes use of ode45.
t=0:.01:10; % explicit time vector
x0=1; % boundary condition
% define function containing my ODE
myODE = @(t,x) -2 .* x^3 + sin( 0.5 .* t) .* x;
% solve ODE with ode45
[tsol,xsol] = ode45(myODE,t,x0);
% plot result as explicit solution points
plot(tsol,xsol,'.')
Kind regards,
Robert

카테고리

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