need help with 4th order runge kutta with multiple 2nd ode

2 Ansichten (letzte 30 Tage)
Noel Lou
Noel Lou am 27 Feb. 2016
Bearbeitet: Noel Lou am 27 Feb. 2016
hi, i would like to ask am i able to use runge kutta for motion equations?
M(d2x/dt2)=Fn(sin θ - uCos θ )
M(d2z/dt2)=Fn(cos θ + uSin θ ) - Mg
Fn,M,θ,u is constant fn/M = 0.866
i tried Mzdoubledot as shown in the code below, however i dont know how to combine Mzdoubledot with Mxdoubledot.
clc; % Clears the screen
clear all;
h=0.1; % step size
thete=30;
g=9.81;
x = 0:h:3; % Calculates upto y(3)
y = zeros(1,length(x));
y(1) = 5; % initial condition
F_xy = @(t,thete) 0.866*(cos(thete)+0.5774*(sin(thete)))-g;
for i=1:(length(x)-1) % calculation loop
k_1 = F_xy(x(i),y(i));
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h; % main equation
end
hold on
plot(x,y,'+-', 'Linewidth', 1.5, 'color', 'blue')
xlabel('x')
ylabel('y')
legend('RK4')

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by