ODE Midpoint Method Help

6 次查看(过去 30 天)
Camila Gill
Camila Gill 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