Question

In: Advanced Math

I need the matlab codes for following question (1) (a). Solve the following second-order differential equations...

I need the matlab codes for following question

(1) (a). Solve the following second-order differential equations by a pair of first-order equations, xyʹʹ − 8x3y3 = 0; with initial conditions y = 0.5 and = −0.5 at x = 1.

(b). Solve the problem in part (a) above using MATLAB built-in functions ode23 and ode45, within the range of 1 to 4, and compare with the exact solution of y = 1/(1 + x2)

[Hint: ode23 à 0.0456, ode45 à 0.0588]

(c). How can we improve the accuracy for the solutions obtained in parts (a) and (b) above?

Solutions

Expert Solution


%%Matlab code for solving ode
clear all
close all
%Answering question b.
%Initial conditions for ode
y0=[0.5;-0.5];
      
        %minimum and maximum x
        xspan=[1 4];
        %Solution of ODEs using ode45 matlab function
        sol1= ode45(@(x,y) odefcn1(x,y), xspan, y0);
        %Equally splitting x into small intervals
        x1 = linspace(xspan(1),xspan(end),501);
        %yy is the corresponding x y v and z
        yy1 = deval(sol1,x1);
        figure(1)
        hold on
        plot(x1,yy1(1,:),'linewidth',2)
      
        %minimum and maximum x
        xspan=[1 4];
        %Solution of ODEs using ode45 matlab function
        sol2= ode23(@(x,y) odefcn1(x,y), xspan, y0);
        %Equally splitting x into small intervals
        x1 = linspace(xspan(1),xspan(end),501);
        %yy is the corresponding x y v and z
        yy2 = deval(sol2,x1);
        figure(1)
     
        plot(x1,yy2(1,:),'linewidth',2)
     
      
        %exact solution
        y_ext=@(x) 1./(1+x.^2);
        plot(x1,y_ext(x1),'linewidth',2)
        hold off
      
title('Plot for y(x) vs. x solution')
xlabel('x')
ylabel('y(x)')
legend('ode45','ode23','Exact solution')
box on
grid on

fprintf('\tAt x=%2.f solution using ode45 is %2.5f.\n',x1(end),yy1(1,end))
fprintf('\n\tAt x=%2.f solution using ode23 is %2.5f.\n',x1(end),yy2(1,end))
fprintf('\n\tAt x=%2.f solution using exact analytic is %2.5f.\n',x1(end),y_ext(x1(end)))


%Function for evaluating the ODE
function dydx = odefcn1(x,y)

    eq1= y(2);
    eq2= (y(2)./x)+8.*x.^2.*(y(1)).^3;
  

    %Evaluate the ODE for our present problem
    dydx = [eq1;eq2];
  
end

%----------------------------End of Code-----------------------------%


Related Solutions

Write the second order differential equation as a system of two linear differential equations then solve...
Write the second order differential equation as a system of two linear differential equations then solve it. y" + y' - 6y = e^-3t y(0) =0   y'(0)=0
Question 4: Homogeneous Second Order Differential equation Solve the following equation for the particular solution. i....
Question 4: Homogeneous Second Order Differential equation Solve the following equation for the particular solution. i. 2?′′ + 5?′ + 3? = 0; ?(0)=3, ?′(0)=−4 ii. 4 (?2?/??2) + 8 (??/??) + 3y = 0 ?(0)=1, ?′(0)=2 iii. ?′′ + 6?′ + 13? = 0; ?(0)=2, ?′(0)=1
This is a Matlab Question Create MATLAB PROGRAM that can solve First Order Linear Differential Equation...
This is a Matlab Question Create MATLAB PROGRAM that can solve First Order Linear Differential Equation ( 1 example contains condition and the other does not have condition). 1. ty′ + 2y = t^2 − t + 1, y(1)=12 The correct answer is y(t) = 1/4 t^2 − 1/3 t + 1/2 + 1/12t^2 2. (x-1) dy/dx + 2y = (x+1)^2 The correct answer is y = (x(x+1) / x-1 ) + C(x+1) / x-1 The correct answer is
define a matlab question and solve with matlab codes (rlc circuts)
define a matlab question and solve with matlab codes (rlc circuts)
Solve the following first order differential equations: (a) 2/?^ ???/?? = 4?^2? ; ?(0) = −1/...
Solve the following first order differential equations: (a) 2/?^ ???/?? = 4?^2? ; ?(0) = −1/ 3 (b) ??/?? + ? = ? ; ?(0) = 5 (c) ??/?? + ? /? = ? 3 ; ? ( 1/2 ) = 1
Question 1 Using MATLAB solve the following system of linear simultaneous equations 3x + 2y -...
Question 1 Using MATLAB solve the following system of linear simultaneous equations 3x + 2y - z = 10........... [1] -x + 3y + 2z = 5........... [2] x - y - z = -1 .................[3] s + 2t - 3u + 4v = 12........... [1] 2s + 2t - 2u + 3v = 10......... [2] t + u = -1............................ [3] s - t + u - 2v = -4................ [4]
I. Solve the homogeneous differential equations with the constant coefficient. a. ? ′′ + 5? ′...
I. Solve the homogeneous differential equations with the constant coefficient. a. ? ′′ + 5? ′ + 6? = 0 b. 4? ′′ − 8? ′ + 3? = 0 ? (0) = 2, ? ′ (0) = ½ II. Solve non-homogeneous differential equations with the indeterminate coefficient method. a. ?′′ − 3? ′ = 5cos(?) b. ? ′ ′ + 5? ′ + 2? ′ = 7? 3? III. Solve non-homogeneous differential equations with the parameter variation method. a....
1. Use Laplace transforms to solve the following differential equations for ?(?) for ? ≥ 0....
1. Use Laplace transforms to solve the following differential equations for ?(?) for ? ≥ 0. Use ?(0) = 0 and ?̇(0) = 1 for each case. i. 0 = ?̈(?) + 2?̇(?) + 4?(?) ii. 0 = ?̈(?) + 3?̇(?) + 2?(?) iii. 5 = ?̈(?) + 5?̇(?) + 6?(?) 3. For the three differential equations from problem one determine the steady-state value of the system using: a. lim?→0 ??(?), b. lim ?→∞ ?(?) analytically, c. lim ?→∞ ?(?)...
This is a question about Ordinary Differential Equations. For solving linear differential equations, I have seen...
This is a question about Ordinary Differential Equations. For solving linear differential equations, I have seen people use the method of integrating factors and the method of variation of parameters. Is it true that either of these 2 methods can be used to solve any linear differential equation? If so, could you show me an example where a linear differential equation is solved using both of these methods. If not, could you explain using examples as to why this is...
We have talked in class about second order differential equations. These equations often arise in applicationsof...
We have talked in class about second order differential equations. These equations often arise in applicationsof Newtons second law of motion. For example, supposeyis the displacement of a moving object with massm. Its reasonable to think of two types of time-independent forces acting on the object. One type - suchas gravity - depends only on positiony. The second type - such as atmospheric resistance or friction -may depend on position and velocityy′. (Forces that depend on velocity are called damping...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT