Question

In: Advanced Math

Solve the frictionless pendulum equation use Runge- kuta 4 or forward Euler ly'' = -g*sin(y) where...

Solve the frictionless pendulum equation use Runge- kuta 4 or forward Euler

ly'' = -g*sin(y)

where g is gravitational acceleration and l is the length of the pendulum. The function y(t) represents the angle of the pendulum with respect to the vertial and y'(t0 the angular velocity. You will need to write the second-order equation as a system of two first-order equations, and you will need to write a function file that will evaluate this system of equations. Plot the solutions y1(t) and y2(t) on the same set of axes. Give an interpretation of y2(t). Set the length to be 1m, and use as initial conditions an initial displacement of pi/2 radians and a 0 rad/sec angular velocity

Solutions

Expert Solution

The Matlab scripts rk4sys.m, dydtSys.m, rk4SysSolver.m are posted below along with the screen shot of the generated plot. Run the script rk4SysSolver.m to generate the plot.

Also, note that the system of first order differential equations are solved using Runge Kutta 4 numerical technique.

rk4sys.m

function [t, yp] = rk4sys(dydt, tspan, y0, h)
% rk4sys: fourth-order Runge-Kutta for a system of ODEs
% [t, y] = rk4sys(dydt, tspan, y0, h): integrates
% a system of ODEs with fourth-order RK method

% input:
% dydt = name of the M-file that evaluates the ODEs
% tspan = [ti, tf]; initial and final times with output
% generated at interval of h, or
% = [t0 t1 ... tf]; specific times where solution output
% y0 = initial values of dependent variables
% h = step size

% output:
% t = vector of independent variable
% yp = vector of solution for dependent variables

ti = tspan(1);
tf = tspan(2);

t = ti: h: tf;
y(1, :) = y0;
yp(1, :) = y(1, :);

for i = 1: length(t)-1
    k1 = dydt( t(i), y(i,:) );
    ymid = y(i, :) + k1 * h/2;
    k2 = dydt( t(i) + h/2, ymid );
    ymid = y(i, :) + k2 * h/2;
    k3 = dydt( t(i) + h/2, ymid );
    yend = y(i, :) + k3 * h;
    k4 = dydt( t(i) + h, yend );
    phi = (k1 + 2 * (k2 + k3) + k4)/6;
    y(i + 1, :) = y(i, :) + phi * h;
    yp(i+1, :) = y(i+1, :);  
end
end

dydtSys.m

function rhs = dydtSys(t, y)
% governing ODE dydt = rhs
% dydt = dydt(t, y)

% input:
% x = independent variable
% y = dependent variable

% output:
% dydt = rhs of the ODE

g = 9.81;
l = 1   ;

dydt1 = y(2);
dydt2 = -g/l * sin( y(1) );
rhs = [dydt1, dydt2];

end

rk4SysSolver.m

clear, close all; clc

tspan = [0, 10];
initConds = [pi/2, 0];
timeStep = 0.1;
[t, y] = rk4sys(@dydtSys, tspan, initConds, timeStep);

y1 = y(:, 1);
y2 = y(:, 2);

figure
plot(t, y(:, 1), '-o', t, y(:, 2), '-s')
xlabel('\bf t')
legend('y_{1}(t)', 'y_{2}(t)')
grid on



Related Solutions

Solve the frictionless pendulum equation use Runge- kuta 4 or forward Euler ly'' = -g*sin(y) where...
Solve the frictionless pendulum equation use Runge- kuta 4 or forward Euler ly'' = -g*sin(y) where g is gravitational acceleration and l is the length of the pendulum. The function y(t) represents the angle of the pendulum with respect to the vertial and y'(t0 the angular velocity. You will need to write the second-order equation as a system of two first-order equations, and you will need to write a function file that will evaluate this system of equations. Plot the...
Use Laplace transforms, solve the differential equation y'' + 16y = 4 sin 4? , where...
Use Laplace transforms, solve the differential equation y'' + 16y = 4 sin 4? , where y(0)=2.    y′(0)=0.
Solve differential equation: y'+y=sin(x)
Solve differential equation: y'+y=sin(x)
Use Classic Runge-Kutta method with h = 1 to solve the system y” - y’ -...
Use Classic Runge-Kutta method with h = 1 to solve the system y” - y’ - 6y = 0, y(0) = 2, y’(0) = 3 on [0,1]
Use the Euler method to solve the following differential equation for the domain [2,2.5]. Use the...
Use the Euler method to solve the following differential equation for the domain [2,2.5]. Use the step-size ℎ = 0.1. ?′=?ln?/? ;?(2)=?1 b) Use the third order Taylor series method to find ?(0.1) and ?(0.2), where ?′=1+2?? ;?(0)=0. Use the step-size ℎ=0.1. c) Solve the problem in part (ii) using the fourth order Runge – Kutta method. d) Solve the problem in part (ii) using the Predictor – Corrector method.
Solve the differential equation by variation of parameters. y''+ y = sin^2(x)
Solve the differential equation by variation of parameters. y''+ y = sin^2(x)
Solve the Following Equation: y'' + y' + y = a*sin(ω*t), y(0) = 0 , y'(0)...
Solve the Following Equation: y'' + y' + y = a*sin(ω*t), y(0) = 0 , y'(0) = 0 Thanks
a) Solve the Cauchy-Euler equation: x^2y'' - xy' + y = x^3 b) Solve the initial-value...
a) Solve the Cauchy-Euler equation: x^2y'' - xy' + y = x^3 b) Solve the initial-value problem: y'' + y = sec^3(x); y(0) = 1, y'(0) =1/2
Use euler method to approiximate y(1) y' is given , solve for y. approiximate y(1) Create...
Use euler method to approiximate y(1) y' is given , solve for y. approiximate y(1) Create a table to show the approximate value of y(1) for each choice of h. y’ = -15y y(0) = 1 h = .25 h = .125 h = .0625 h = .03125
Use method of variation of parameters to solve y'' + y = sin^2(x)
Use method of variation of parameters to solve y'' + y = sin^2(x)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT