# ODE Midpoint Method Help

1 Ansicht (letzte 30 Tage)
Camila Gill am 13 Mär. 2020
Kommentiert: James Tursa am 13 Mär. 2020
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).
% 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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
James Tursa am 13 Mär. 2020
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.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by