My Math Forum  

Go Back   My Math Forum > Math Forums > Math Software

Math Software Math Software - Mathematica, Matlab, Calculators, Graphing Software


Reply
 
LinkBack Thread Tools Display Modes
February 29th, 2016, 11:16 AM   #1
Newbie
 
Joined: Feb 2016
From: singapore

Posts: 1
Thanks: 0

Runge kutta help!

how do i use runge kutta on a 2nd order equations?

M(d2x/dt2)=Fn(sin θ - uCos θ )
M(d2z/dt2)=Fn(cos θ + uSin θ ) - Mg


i tried Mzdoubledot as shown in the code below, however i dont know how to combine Mzdoubledot with Mxdoubledot.

Fn,M,θ,u is constant fn/M = 0.866

clc; % Clears the screen
clear all;

thete=30;
g=9.81; %Constant

h=0.1; % step size
tfinal = 3;
N=ceil(tfinal/h);

%y = zeros(1,length(x));
t(1) = 0; % initial condition
y(1) = 5;

F_zy = @(t,thete) 0.866*(cos(thete)+0.5774*(sin(thete)))-g;
F_xy = @(t,thete) 0.866*(sin(thete)-0.5774*(cos(thete)));

for i=1:N % calculation loop

%update time
t(i+1)=t(i)+h;
%update motions
k_1 = F_xy(t(i),y(i));
k_2 = F_xy(t(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((t(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((t(i)+h),(y(i)+k_3*h));
k_11 = F_zy(t(i),y(i));
k_22 = F_zy(t(i)+0.5*h,y(i)+0.5*h*k_11);
k_33 = F_zy((t(i)+0.5*h),(y(i)+0.5*h*k_22));
k_44 = F_zy((t(i)+h),(y(i)+k_33*h));

y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;
y(i+1) = y(i) + (1/6)*(k_11+2*k_22+2*k_33+k_44)*h;% main equation
end

hold on
plot(t,y,'+-', 'Linewidth', 1.5, 'color', 'blue')
xlabel('time')
ylabel('height')
legend('RK4')
noelsg is offline  
 
Reply

  My Math Forum > Math Forums > Math Software

Tags
kutta, runge, runge-kutta



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runge-Kutta praveengummadi35 Calculus 0 March 27th, 2014 05:58 PM
Runge Kutta ODE Solver 0nad Applied Math 1 October 2nd, 2012 10:20 AM
runge kutta method thunderkasi Real Analysis 1 October 25th, 2011 04:15 AM
Implemetation of Runge-Kutta UlrichRekenin Calculus 0 August 22nd, 2011 10:54 AM
Runge-Kutta Mathematica mathmoron Math Software 1 April 8th, 2010 06:35 AM





Copyright © 2019 My Math Forum. All rights reserved.