Solving an ODE using RungeKutta methods.

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hey,

I have to model a projectile for some work for school (by solving an ode). I have successfully done so using Euler's methods, but am also required to solve them using the Runge Kutta method. This is where I run into a problem. The derived 4th order Runge Kutta method requires that the inputs for your function of acceleration look something like this FUNCTION(time increment,distance,velocity), my function for acceleration however is more like FUNCTION(time increment, velocityx , velocityy). I work out the distance traveled by the projectile afterwards. this works fine for Euler's but not for the Runge Kutta method. Is there a derivation of it that would allow me to calculate it with the inputs I have? 

This is my code for the runge kutta method:

% Move the problem one step forward in time using Runge Kutta
function [x, xd, xdd] = oneStepRungeKutta(t, x, xd, tInc)

%Calculate current acceleration
xdd = acceleration(t, x, xd);

%Calculate next displacement and velocity
A=(tInc/2)*(acceleration(t,x,xd));
Beta=(tInc/2)*(xd+A/2);
B=(tInc/2)*(acceleration(t+tInc/2,x+Beta,xd+A));
C=(tInc/2)*(acceleration(t+tInc/2,x+Beta,xd+B));
Delta=tInc*(xd+C);
D=(tInc/2)*(acceleration(t+tInc,x+Delta,xd+2*C));
x = x + tInc*(xd+(1/3)*(A+B+C));
xd = xd + (1/3)*(A+2*B+2*C+D);


but it requires my acceleration funtion to be in the form of FN(t,x,xd) and I want it to be in the form of FN(t,xd,xy). Is this even possible?

This might not make any sense! If that is the case, I'm sorry. Its probably that try as I might I cannot get my head around the Runge Kutta method. Any help or input would be greatly appreciated.

Thanks!
0
Reply Francisco 12/5/2010 7:17:05 AM

See related articles to this posting

comp.soft-sys.matlab 203662 articles. 536 followers. Post

0 Replies
1115 Views

Similar Articles

[PageSpeed] 36


Reply:

Similar Artilces:

solving pde by method of lines using ode solver
Dear all, I am trying to solve PDE's by discretizing the space domain equations using finite difference scheme (method of lines) and solving the resultant ode's using ode solver ode15s. I am facing two problems 1. Warning: Failure at t=3.834179e-13. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.362174e-27) at time t Even if I reduce the absolute and relative tolerances, I am not able to solve this problem 2. I am trying to look at the time taken by individual expression in the code using the inbulit utility profile. The ti...

Use Runge-Kutta method solve ODE(with code inside)
Hi all! I'm trying to solve a ODE with RK4 method,but i can't get the solution. The differential equation of the considered non-linear system is given by: m*d^2y(t)/dt^2+c*dy(t)/dt+k1y(t)+k2y(t)^2+k3y(t)^3=u(t) in which m,c,k1,k2,k3 are all constants and input u(t) is given by: 3*[sin(110*pi*t)-sin(60*pi*t)]/(2*pi*t) t=-511*0.005 sec,.....,512*0.005 sec I have to obtain the output y(t) using RK4 method,here is my code: (1) write ode file first(de1.m) function de=de1(t,Y); % Y is a column vector global m c k1 k2 k3 y=Y(1,:);v=Y(2,:); ...

where can I fine the function.m using newmark method to solve a ODE?
the equation is M x''+ C x' +K x=f(t) Hi, pls goto http://mail.bris.ac.uk/~aemtak/numint/numint.html On 21 Dec 04 08:05:10 -0500 (EST), Lijun wrote: >the equation is > >M x''+ C x' +K x=f(t) ...

solving ODE using consistency(solid) and non-consistency numerical methods
please could anyone help me...I am looking for a MATlab code to solve ODE using consistency(solid) and non-consistency numerical methods..if anyone has some examples for me I would be grateful...Thanks ...

record second derivative in a function used to solve ODE using ode45
Hi all, I have a problem with a function used to define a 2nd order nonlinear ODE for ode45. The function goes like this: function [Rdot] = km2bode(t,R) Rdot(1) = R(2); Rdot(2) = %a complicated expression dependent on some variables, such as R(1) and R(2). Rdot = Rdot'; The problem is I need the values of Rdot(2) as the time progresses later in my calculation. However if I run something like: options = odeset('RelTol',1e-10,'AbsTol',1e-10); [T,R] = ode45('km2bode', timespan, [ km.r0 initVelo], options) The values of Rdot(2) will not be saved...

how to use interp1 function for time dependant funcyion in ODE (ODE solved for space points for each time instant)
dear friends, i have a small problem. i want to solve a set of9 differential equations using MOL for visualization of a field in space and time. i am using interp1 function to insert a time dependant function into a differential equation which is solved by an ODE solver. below is a part from my code, k_p=interp1(t1,k_p,t); dydt(1)=(gamma_31/2)*y(3)+(i/2)*(k_p+k_d).*y(7)-(i/2)*(k_p+k_d).*y(4); if i run the ODE solver for the given number of space points and insert the interp1 function like this, will this work correctly? i have ran my program but i think the result is not correct. i ...

Solving an ODE and using interp1
I need to interpolate some data to use in a system of ODEs and then solve the system (using ode45, or similar). On the MathWorks documentation (see the main page on solving ODEs), they have a solution with the interpolation in the definition of the ODE. I can do this, however, I need to repeatedly call the ODE as part of a (fminsearch) parameter search. I belive that the computation would be faster if the program could do the interpolation once, outside of the ODE, instead of every time the ODE is called. I've tried several methods of creating a function (or script) that interpolates...

using Interpolation to solve ODEs
Dear friends I have a coupled ODEs, In[1]:= e1 = x1[t]* (-27 + 4 x1[t]^2) - 4 (1 + x1[t]^2)* y1'[t]; In[2]:= e2 = y1[t] *(-27+ 4 (x1[t]^2 + y1[t]^2)) + 4 (1 + x1[t]^2 + y1[t]^2) *x1'[t]; Given the initial values of x1[0] and y1[0],we can use NDSolve command to solve them In[3]:= s=NDSolve[{e1==0,e2==0,x1[0]==1,y1[0]==0},{x1,y1},{t,0,20}]; Now I want to solve them using another way( Because they are the simplest cases. The actually form I have to deal with can not be obtained obviously). At first I generate the data for the fist part of right hand side(RHS) of e1 as I...

How to use ODE 15s to solve this equation.
Could someone please elaborate on how to use ODE 15s or 45 for this differential equation? (1/beta) *(d alpha/dT) = ln A*(1-alpha)- (E/RT) I have the value of alpha and E as a function of a. I need to generate graph of alpha Vs Temperature and d alpha/dT versus Temperature. On 6/24/2012 7:59 PM, Sriraam wrote: > Could someone please elaborate on how to use ODE 15s or 45 for this differential equation? > > (1/beta) *(d alpha/dT) = ln A*(1-alpha)- (E/RT) > > I have the value of alpha and E as a function of a. > > I need to generate graph of alpha Vs Tempera...

solving ODE using finite difference
HI Please i want to know how to register my new MATLAB program which solve wide range of ODE, and what is the advantages which i will obtain from mathworks if there is a gournal which i must send my program first to it,what it is name many thanks ...

Problem using feval to solve ODEs
Hey all, I've tried posting this before, but I did not have much luck with the help given. I've decided to post all that I have and to let someone help me on this. I'm a chemical engineering student, not a computer scientist, which may be half my problem, but thank you all in advance. ***Basically, I would like to be able to solve my differential equations at specific points in time so that I can compare it to the "Data for comparison" below. I have been told feval is the built in function to use, but I have been having real difficulties trying to use it in that manner....

Solving odes using distributed computing
Hi, I would be thankful for some help on this: I am trying to solve coupled pde problem using method of lines. Therefore I end up with a large system of odes. Is it possible to use distributed computing to solve this large system of ode in Matlab to increase efficiency? Searching through the newsgroup I have not seen anything that helps. Thanks Mmd. On Nov 4, 10:01=A0am, "Mmd " <hp...@newcastle.edu.au> wrote: > Hi, > I would be thankful for some help on this: > > I am trying to solve coupled pde problem using method of lines. =A0Theref= ore I end up with a l...

Solve equation using Newton-Raphson method
Hello, Say I have some equation in terms of constants a, b and c, and variables x and y(x): a*y^2*ln(y) - y^2 + b - 4*c*(y-1)*x + a*b*(y^2-1) = 0 The problem I have been given is to solve this equation for y(x) as a function of x, using the Newton-Raphson method. (I.e. solve y(x) in terms of the variable x and constants a,b,c). How do I go about doing this? I'm lost as to how to solve this using the Newton-Raphson method in particular. Thanks, Graham On Aug 31, 3:56=A0am, "Graham " <gra...@peyton.co.za> wrote: > Hello, > > Say I have some equ...

Help in solve eq using ODE (Emergency)
Hi I have an eq. like dy/dt=y(t).y(t-t0)+g(t) t0 is constant. How should I use ODE to solve it? Dear ehsan, > I have an eq. like dy/dt=y(t).y(t-t0)+g(t) > t0 is constant. > How should I use ODE to solve it? Do you want to solve this numerically or analytically? At first you have to find out, if the problem is stiff or not. What is "g(t)"? For a non-stiff problem, see the documentation of e.g. ODE45. A stiff problem can be solved by ODE15S. Good luck, Jan On Oct 23, 3:25=A0pm, "ehsan " <hemmati2...@yahoo.com> wrote: > Hi > I have an...

how to use ode solve implicit differential equations?
Dear friends, Is it possible to use ode solver if my differential euqation is f(t,y,y_prime)=0? Function f includes a double intergration with it. If not possible, what other methods or combination of method may be used? Thank you very much. rayman ...

Help me to solve coupled ode using matlab
I have programed system of six coupled ode listed below in matlab.But i dont know how to solve these equations using Predictor corrector and RK-4th order method. Please help me in solving these equations. function [GG ] = myfun_rafiq(t,x) % ----- State Variables Selection % x1 = nw, x2 = Nw, x3 = nc, x4 = Nc, x5 = np, x6 = Np % ----- Parameters sigmaEjQj = 793.7; EiQi =700; EpQp = 13.7; EcQc = 80; EfQf = 0; Vc = 9.08e6; Vw = 1.37e7; Vp = 1.37e6; lk = 0.0; Kc = 40.0; Kp = 6.90; f_t = 1; sigma = 13.4e-24; fn = 1; ...

Using pdepe to solve a system of both pdes and odes
Hello, I'm trying to solve a system of five 5 differential equations: 2 ODEs and 3 PDEs. Pdepe keeps giving me the error "This DAE appears to be of index greater than 1" and I'm not sure if it's a bug in my code or if the problem I'm trying to solve isn't possible in Matlab. My code is below and any advice or insights you could give on how to proceed would be much appreciated. Thank you, Layla ----- function solve_pde m = 2; r = 0:0.05:2; t = 0:10:200; sol = pdepe(m,@pde,@pde_ic,@pde_bc,r,t); u1 = sol(:,:,1); u2 = sol(:,:,2); u3 = sol(:,:,3); u4 = sol(:,:,4...

help solving an ODE equation using ode45?
I have a second order ODE (ordinary differential equation): x_doubledot + x_dot*0.25 - x + x^3 = 0.3*cos(t) where: x(0)=0 , x_dot(0)=1 and 0<=t<=60 s I need to solve this using ode45. Anybody up to doing this? I'm new at this and have no idea. Cheers "Grant W" <grant_wilburn@hotmail.com> wrote in message news:ef1781e.-1@webx.raydaftYaTP... >I have a second order ODE (ordinary differential equation): > > x_doubledot + x_dot*0.25 - x + x^3 = 0.3*cos(t) > > where: > > x(0)=0 , x_dot(0)=1 and 0<=t<=60 s > > I need to solve this us...

Solving ODE IVP (using ode45 and ode23s)
Dear Sirs, I was using my own short programs based on Runge-Kutta-Fehlberg and other methods for ODE IVP�.. In the future I would like to use the Matlab functions (ode45, ode23s�), since Matlab functions have much better step-size prediction than the ones coded by me�So, here is the question: y�=f(t,y); y(0)=y0� My problem is defined in such a way, that the function �f� is not entirely known in advance, but is calculated step by step while the solution progresses. The evaluation of the function value f is feasible only near the current step�. The function f is not analytically given, but is...

solving OCP using legendre PS method
hellow , I use the legendre pseudospectral method to solve an OCP problem, this method is called like this because the states/controls are approximated by the legendre polynomial of degree N on the legendre-gauss-lobatto nodes .... ,so i use this method to transform my continuous OCP into a discrete OCP which i can solve by using the matlab function "fmincon". my problem is the following : my program is working for 10 or 20 LGL nodes, theses nodes are reals and i get the solution that i want. But!!! for 50 LGL nodes (some of the LGL nodes are complexes) my program is not converging...

Solving ode using distributed processing toolbox
Is it possible to use the distributed processing toolbox for an ode solver. My input to ode being large, it takes a large time to solve it "Rishab " <rishab.civil@gmail.com> wrote in message <god7ep$n69$1@fred.mathworks.com>... > Is it possible to use the distributed processing toolbox for an ode solver. My input to ode being large, it takes a large time to solve it Hi Rishab, were you able to find a solution to your question? i am also interested in this. ...

I want to solve this question using Newton-Raphson method
I want solve BtanB=h0L/K, where h0 is the convection coefficient, K is the thermal conductivity, and 2L is the thickness of the slab. Determine the smallest root(value of B=beta) of the equation for slab with h0L/K=0 On 5/16/2012 10:39 AM, Bismark wrote: > I want solve > BtanB=h0L/K, > where h0 is the convection coefficient, K is the thermal conductivity, and 2L > is the thickness of the slab. > Determine the smallest root(value of B=beta) of the equation for slab with h0L/K=0 if h0L/K=0, then we have B tan(B) =0 or tan(B) =0 or B=0,pi,-pi,2 pi...

How to code and solve wave equation using LAx method
Sir I am new in matlab. I want to solve this problem using matlab coding. Code and Solve The 1st order wave equation Code and solve the 1st order (1-D) wave equation Ut + 0.75 Ux=0 using the Lax&#8217;s method. Use the following parameters 0&#8804;x&#8804;1 &#8710;x=0.05,0.02,0.01 V=0.75,0.5 Initial condition U(0,x) = Sin(6&#960;x) Periodic Boundary Conditions Predict the amplitude and phase errors after time = 0.5 . Waiting for your response. THANKS IN ANTICIPATION On 12/27/2010 5:30 AM, Ayaz Ahmad wrote: > Sir > I am new in matlab. I want to solve...

Any ODE solving technique using discretely measured input?
Dear all I am trying to simulate nonlinear state equations with Matlab ode15s, one of variable time step method. Briefly, the system is... x' = g(t, x, paramters) + F(t) where, I have F(t) as a vector of numbers, with size N from experimental measurement. It's not continuous function of time such as sin(t). How can I code this in sub-function which has state equations? I found that interpolation or spline is one of the way to approximate my measurement from past postings in this goole. Could anybody provide more hints or scratch code, please? Or any other way to solve my proble...