Question

In: Advanced Math

Consider the following second-order ODE, y"+1/4y=0 with y(0) = 1 and y'(0)=0. Transform this unique equation...

Consider the following second-order ODE,

y"+1/4y=0

with y(0) = 1 and y'(0)=0.

Transform this unique equation into a system of two 1st-order ODEs.

Solve the obtained system for t in [0,0.6] with h = 0.2 by MATLAB using Euler Method or Improved Euler Method.

Solutions

Expert Solution


%Matlab code for Euler and Heun's and RK4 method for 2d ODE
clear all
close all
%functions for Euler and Huen method

f=@(t,y1,y2) y2;
g=@(t,y1,y2) (-1/4)*y1;

fprintf('Here let us consider\n')
fprintf('\tdx/dt=f(t,y1,y2)=y2\n')
fprintf('\tdy/dt=g(t,y1,y2)=-(1/4)*y1\n')
%step size
h=0.2;

%Initial guess
y1_0=1; y2_0=0;

y1_euler(1)=y1_0; y2_euler(1)=y2_0;

t_euler(1)=0; t_end=0.6;
n=(t_end-t_euler(1))/h;

%iteration for y1 and y2 using Euler method
fprintf('Iterations for y1 and y2 using Euler method\n\n')
fprintf('Initial condition for y1(0)=%f and y2(0)=%f .\n',y1_0,y2_0)
fprintf('Euler iterations\n')
for i=1:n+1
    fprintf('After %d iterations \n',i)
    t_euler(i+1)=t_euler(i)+h;
    y1_euler(i+1)=y1_euler(i)+h*f(t_euler(i),y1_euler(i),y2_euler(i));
    y2_euler(i+1)=y2_euler(i)+h*g(t_euler(i),y1_euler(i),y2_euler(i));
    fprintf('\tt_euler(%d+1)=t_euler(%d)+h=%f\n',i,i,t_euler(i+1));
    fprintf('\n\ty1_euler(%d+1)=y1_euler(%d)+h*f(t_euler(%d),y1_euler(%d),y2_euler(%d))=%f\n',i,i,i,i,i,y1_euler(i+1))
    fprintf('\ty2_euler(%d+1)=y2_euler(%d)+h*g(t_euler(%d),y1_euler(%d),y2_euler(%d))=%f\n',i,i,i,i,i,y2_euler(i+1))
end
fprintf('\n\t Using Euler method at t=%f ,y(%f)=%f\n',t_euler(end),t_euler(end),y1_euler(end))
%iteration for y1 and y2 using Huen method
fprintf('\n\nIterations for x and y using Heun method\n\n')
fprintf('Initial condition for x(0)=%f and y(0)=%f .\n',y1_0,y2_0)
y1_huen(1)=y1_0; y2_huen(1)=y2_0;
t_huen(1)=0; t_end=0.6;
n=(t_end-t_huen(1))/h;

for i=1:n+1
    fprintf('After %d iterations \n',i)
    t_huen(i+1)=t_huen(i)+h;
    k1=h*f(t_huen(i),y1_huen(i),y2_huen(i));
    l1=h*g(t_huen(i),y1_huen(i),y2_huen(i));
    fprintf('\tt_heun(%d+1)=t_heun(%d)+h=%f\n',i,i,t_huen(i+1));
    fprintf('\tk1=h*f(t_huen(%d),y1_huen(%d),y2_huen(%d))=%f\n',i,i,i,k1)
    fprintf('\tk1=h*g(t_huen(%d),y1_huen(%d),y2_huen(%d))=%f\n',i,i,i,l1)
  
    k2=h*f(t_huen(i+1),y1_huen(i)+k1,y2_huen(i)+l1);
    l2=h*g(t_huen(i+1),y1_huen(i)+k1,y2_huen(i)+l1);
    fprintf('\tk2=h*f(t_huen(%d+1),y1_huen(%d)+k1,y2_huen(%d)+l1)=%f\n',i,i,i,k2)
    fprintf('\tl2=h*g(t_huen(%d+1),y1_huen(%d)+k1,y2_huen(%d)+l1)=%f\n',i,i,i,l2)
  
    y1_huen(i+1)=y1_huen(i)+(1/2)*(k1+k2);
    y2_huen(i+1)=y2_huen(i)+(1/2)*(l1+l2);
    fprintf('\n\ty1_huen(%d+1)=y1_huen(%d)+(1/2)*(k1+k2)=%f\n',i,i,y1_huen(i+1))
    fprintf('\ty2_huen(%d+1)=y2_huen(%d)+(1/2)*(l1+l2)=%f\n',i,i,y2_huen(i+1))
end
fprintf('\n\t Using Modified Euler method at t=%f ,y(%f)=%f\n',t_huen(end),t_huen(end),y1_huen(end))
%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%


Related Solutions

Use Laplace Transforms to solve the following second-order differential equation:   y"-3y'+4y=xe2x where y'(0)=1 and y(0)=2
Use Laplace Transforms to solve the following second-order differential equation:   y"-3y'+4y=xe2x where y'(0)=1 and y(0)=2
Use the Laplace transform to solve y'' + 4y' + 5y = 1, y(0)= 1, y'(0)...
Use the Laplace transform to solve y'' + 4y' + 5y = 1, y(0)= 1, y'(0) = 2
Solve with Laplace transform 1. y''+ 4 t y'− 4y = 0, y(0) = 0, y'(0)...
Solve with Laplace transform 1. y''+ 4 t y'− 4y = 0, y(0) = 0, y'(0) = −7 2. (1− t) y''+ t y' − y = 0, y(0) = 3, y'(0) = −1
Solve the following differential equation: y''+4y'+4y=u(t-1)-u(t-3), y(0)=0, y'(0)=0
Solve the following differential equation: y''+4y'+4y=u(t-1)-u(t-3), y(0)=0, y'(0)=0
Given a second order ode m y’’  + c y’ + k y = 0 with  m, c...
Given a second order ode m y’’  + c y’ + k y = 0 with  m, c and k all positive.  (like a mass‐spring system with damping) Argue that the solution will always be damped; the exponential portion can never be positive regardless of the particular m, c and k.
using the Laplace transform solve the IVP y'' +4y= 3sin(t) y(0) =1 , y'(0) = -...
using the Laplace transform solve the IVP y'' +4y= 3sin(t) y(0) =1 , y'(0) = - 1 , i am stuck on the partial fraction decomposition step. please explain the decomposition clearly.
Consider the following second-order ODE: (d^2 y)/(dx^2 )+2 dy/dx+2y=0 from x = 0 to x =...
Consider the following second-order ODE: (d^2 y)/(dx^2 )+2 dy/dx+2y=0 from x = 0 to x = 1.6 with y(0) = -1 and dy/dx(0) = 0.2. Solve with Euler’s explicit method using h = 0.4. Plot the x-y curve according to your solution.
la place transform of 1. y´´+4y´+3y=0. y(0)=3, y´(0)=1 2. y´´+2y´+y=0. y(0)=1, y´(0)=1
la place transform of 1. y´´+4y´+3y=0. y(0)=3, y´(0)=1 2. y´´+2y´+y=0. y(0)=1, y´(0)=1
la place transform of 1. y´´+4y´+6y_=0, y(0)=1, y´(0)=-4 2. y´+y=t^2 , y(0)=0
la place transform of 1. y´´+4y´+6y_=0, y(0)=1, y´(0)=-4 2. y´+y=t^2 , y(0)=0
use laplace transform to solve the initial value problem: y''+4y=3sint y(0)=1, y'(0)=-1
use laplace transform to solve the initial value problem: y''+4y=3sint y(0)=1, y'(0)=-1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT