필터 지우기
필터 지우기

ODE Midpoint Method Help

조회 수: 6 (최근 30일)
Camila Gill
Camila Gill 2020년 3월 13일
댓글: James Tursa 2020년 3월 13일
Trying to write a function that implements 1-step of ODE Runge Kutta Midpoint Method. Function references another function containing eqaution (not sure if fn calls function correctly).
The function will not solve for k1 and k1 therfore i can not solve for y(i+1).
Please help.
% Implements 1-step of Mid-point Method
function xnew = midpointstep_CGill(tint, x, h, fn)
global ode
syms x(t) dx(t)
h = .01; % Step Size
tint = 0:h:25; % Time interval [mint, maxt]
x(0) == 0; % Inital Condition
dx(0) == 30; % Inital Condition
fn = ode3dp_CGill(ode);
for i = 1:(length(tint)-1)
k1 = fn(x(i),dx(i));
k2 = fn(x(i) + 0.5*h, dx(i) + 0.5*h*k1);
y(i+1) = y(i) + k2*h;
end
end
Calls the following function
% Computes ODE values
function ode = ode3dp_CGill(t,x)
global ode
syms x(t) dx(t) m b k F(t)
F = -sin(4*pi*t);
eq = m*dx(t) + b*x(t) + k*x == F;
eq = subs(eq, [b], [2*(k*m)^(1/2)]);
ode = collect(eq, m)/m;
end
  댓글 수: 1
James Tursa
James Tursa 2020년 3월 13일
What is the ODE you are trying to solve? You've got b*x(t) and k*x in your equation so I am not sure what exactly the ODE is.

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

답변 (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