Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) Using a computer system (preferably MatLab, Octave, Python, C, C++, etc.) fi

ID: 3754430 • Letter: #

Question

(a) Using a computer system (preferably MatLab, Octave, Python, C, C++, etc.) find the approximate solution to

y = x^2 + y^2 y(0) = 0

using a step size of h = 0.1. Write down the approximate values of y(1),y(2) and y(3).

(b) Repeat with a step size of h = 0.01, writing out the approximate values of y(1), y(2) and y(3).

(c) Recall our discussion on the interval over which solutions exist. Do you think the solution of this initial value problem exists for x (0, 3)? If not, over what interval to you suspect it exists on? You may want to plot your approximate solution to help answer this.

Please also attach your code for part (a).

Explanation / Answer

USING PYTHON

# denotes the derivative equation given i.e. y = x^2 + y^2

def y_derivative(x, y):

    return x ** 2 + y ** 2

  

# method to print the solution for y(1), y(2) and y(3)

def find_solutions(yi, h):

    # x0 will be step size

    xi = h

    # this will contain all our values

    solutions = []

    # looping through to get the values for y(1), y(2) and y(3)

    for i in range(0, 3):

        # represents the formula y(n) = y(n-1) + h * f(x(n-1), y(n-1))

        y = round(yi + h * y_derivative(xi, yi), 5)

        # after rounding it off, appending it to the solutions list

        solutions.append(y)

        yi = y

        xi += h

    # printing out the values

    for i, value in enumerate(solutions, 1):

        print('y({}) = {}'.format(i, value))

  

  

# 1. with h = 0.1

h = 0.1

y0 = 0

find_solutions(y0, h)

  

# 2. with h = 0.01

h = 0.01

y0 = 0

find_solutions(y0, h)

OUTPUTS

1. for h=0.1

y(1) = 0.001
y(2) = 0.005
y(3) = 0.014

2.for h=0.01

y(1) = 0.0
y(2) = 0.0
y(3) = 1e-05