Question: Question 1 Write a function numerical_integration() in MATLAB that can perform numerical integration. It should intake the following inputs: 1. a vector of x-axis values
Question 1 Write a function numerical_integration() in MATLAB that can perform numerical integration. It should intake the following inputs: 1. a vector of x-axis values representing the range over which we are integrating, for instance, [0.0.01:40] if we are integrating over the range 0 to 40 with a d-step of 0.01. 2. the derivative function over the given x-axis values. 3. the initial condition for the first value of the integral. 4. the step size of the numerical integral (the d-step used in x-axis vector) 5. the analytical solution for the integral over the given x-axis values Your function should compute the numerical integral and return it, in addition to plotting it. So for instance, if: 1.xis (-2'pi:0.01:2'pi) 2. derivative function is cos(x) 3. initial condition is o 4. step size of 0.01 5. analytical value is sin(x) Then we run: X y -2pit0.01:2-pi; numerical_integration(x, cos(x), 0, 0.01, sin(x)); We should see a figure pop up and y should be a numerical estimation of sinx). Submit your function m-file here. Upload Choose a File Question 1 Write a function numerical_integration() in MATLAB that can perform numerical integration. It should intake the following inputs: 1. a vector of x-axis values representing the range over which we are integrating, for instance, [0.0.01:40] if we are integrating over the range 0 to 40 with a d-step of 0.01. 2. the derivative function over the given x-axis values. 3. the initial condition for the first value of the integral. 4. the step size of the numerical integral (the d-step used in x-axis vector) 5. the analytical solution for the integral over the given x-axis values Your function should compute the numerical integral and return it, in addition to plotting it. So for instance, if: 1.xis (-2'pi:0.01:2'pi) 2. derivative function is cos(x) 3. initial condition is o 4. step size of 0.01 5. analytical value is sin(x) Then we run: X y -2pit0.01:2-pi; numerical_integration(x, cos(x), 0, 0.01, sin(x)); We should see a figure pop up and y should be a numerical estimation of sinx). Submit your function m-file here. Upload Choose a File
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
