Question

Using the Script: function EulerMethod1(n) X = 0 : 1/n : 1 ; Y = zeros(...

Using the Script:

function EulerMethod1(n)

X = 0 : 1/n : 1 ;

Y = zeros( 1, n + 1 ) ;

Y(1) = 1 ;

for k = 1 : n

m = Y(k) ;

Y(k + 1) = Y(k) + m*( X(k + 1) - X(k) ) ;

end

clf

plot( X, Y )

Create a new script, which defines the function EulerMethod2. The purpose of EulerMethod2 is to use Euler's Method to approximate the solution to the Initial Value Problem given below.

      dy/dx = 2xy        where.           y (0) = 1.          over the interval. [ 0, 2 ]

Homework Answers

Answer #1

Required Matlab code with explanatory comments where changes were made is given below:

function EulerMethod2(n)

X = 0 : 1/n : 2 ; %changed to 0:1/n:2 as we need solution over [0 2]

Y = zeros( size(X) ) ; %change so Y and X have same sign

Y(1) = 1 ;

for k = 1 : length(X)-1

m = 2*X(k)*Y(k) ; %changed to y'=f(x,y)=x*y

Y(k + 1) = Y(k) + m*( X(k + 1) - X(k) ) ;

end

clf

plot( X, Y )

Resulting plot:

Hope this was helpful. Please do leave a positive rating if you liked this answer. Thanks and have a good day!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Your objective in Problem 2 is to employ Euler's Method to determine what goes wrong when...
Your objective in Problem 2 is to employ Euler's Method to determine what goes wrong when the interval is [ 0, 1 ]. To this end, I want you to create another new script, EulerMethod3, which is intended to approximate the "solution" to the IVP given below.          dy/dx = (1/9)*(y^10)        where.          y(0) = 1.            over the interval. [ 0, 1 ] I was given the code below for a different question, but I don't know how to modify it to solve this...
Using Euler's method Calculate the exact solution and investigate the accuracy of your approximations. dy/dx=x-xy y(1)=0...
Using Euler's method Calculate the exact solution and investigate the accuracy of your approximations. dy/dx=x-xy y(1)=0 dx=0.2
Consider the initial value problem given below. y' = (x+y+1)2 , y(0)= -1 The solution to...
Consider the initial value problem given below. y' = (x+y+1)2 , y(0)= -1 The solution to this initial value problem crosses the x-axis at a point in the interval [0, 1.4]. By experimenting with the improved Euler's method subroutine, determine this point to two decimal points.
Use Euler's method to approximate y(1.2), where y(x) is the solution of the initial-value problem x2y''...
Use Euler's method to approximate y(1.2), where y(x) is the solution of the initial-value problem x2y'' − 2xy' + 2y = 0,  y(1) = 9,  y'(1) = 9, where x > 0. Use h = 0.1. Find the analytic solution of the problem, and compare the actual value of y(1.2) with y2. (Round your answers to four decimal places.) y(1.2) ≈     (Euler approximation) y(1.2) =     (exact value)
1)Consider the following initial-value problem. (x + y)2 dx + (2xy + x2 − 2) dy...
1)Consider the following initial-value problem. (x + y)2 dx + (2xy + x2 − 2) dy = 0,   y(1) = 1. Let af/ax = (x + y)2 = x2 + 2xy + y2. Integrate each term of this partial derivative with respect to x, letting h(y) be an unknown function in y. f(x, y) =   + h(y) Solve the given initial-value problem. 2) Solve the given initial-value problem. (6y + 2t − 3) dt + (8y + 6t − 1) dy...
1)  Consider the following initial-value problem. (x + y)2 dx + (2xy + x2 − 2) dy...
1)  Consider the following initial-value problem. (x + y)2 dx + (2xy + x2 − 2) dy = 0,   y(1) = 1 Let af/ax = (x + y)2 = x2 + 2xy + y2. Integrate each term of this partial derivative with respect to x, letting h(y) be an unknown function in y. f(x, y) =    + h(y) Find the derivative of h(y). h′(y) = Solve the given initial-value problem. 2) Solve the given initial-value problem. (6y + 2t − 3) dt...
Consider the initial value problem dy/dx= 6xy2 y(0)=1 a) Solve the initial value problem explicitly b)...
Consider the initial value problem dy/dx= 6xy2 y(0)=1 a) Solve the initial value problem explicitly b) Use eulers method with change in x = 0.25 to estimate y(1) for the initial value problem c) Use your exact solution in (a) and your approximate answer in (b) to compute the error in your approximation of y(1)
Solve the 1st-order linear differential equation using an integrating fac- tor. For problem solve the initial...
Solve the 1st-order linear differential equation using an integrating fac- tor. For problem solve the initial value problem. For each problem, specify the solution interval. dy/dx−2xy=x, y(0) = 1
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method...
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method (use the form of second-order Runge-Kutta method, Eqs(10.65),(10.66)). For function name and arguments use [x,y]=odeMIDPOINT(ODE,a,b,h,yINI). The input argument ODE is a name for the function that calculates dy/dx. It is a dummy name for the function that is imported into odeMIDPOINT. The arguments a and b define the domain of the solution, h is step size; yINI is initial value. The output arguments, x...
Using Taylor series expansion method; find a series solution of the initial value problem (x2+1)d2y/dx2+xdy/dx+2xy=0 y(0)=2...
Using Taylor series expansion method; find a series solution of the initial value problem (x2+1)d2y/dx2+xdy/dx+2xy=0 y(0)=2 y'(0)=1