フィルターのクリア

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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by