Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Python In this problem we will use recurrence relations to compute an integral and determine the relative and absolute error associated with each of
Using Python
In this problem we will use recurrence relations to compute an integral and determine the relative and absolute error associated with each of them. As an aside (not required) you should be able to verify both the recurrence relation on your own. Now, consider the integral Ik = 1 ze" da where lo =1-1/e Evaluate the integrals In and store them in an array, 11, using the 'Forward Recurrence Relation' defined as follows: Ix=1-klx-1 ke 1, 2, 3, ....., nmax We would now use a 'Backward Recurrence Relation' to determine the integrals. Assume that Ik = 0 for k = nmax. Using this and the recurrence relation provided below, evaluate the integrals and store them in an array named 12: Ix-1= (7 ) ke nmax, ........., 1 Now let us evaluate the error associated with both the schemes. Calculate the exact integral using the provided function func_int which takes the input k and returns the integral IR. Calculate the integral for all the k values in the array [1, 2, 3,..., nmax). Calculate the absolute and relative errors associated with the forward recurrence relation and store them in arrays abserri and relerri respectively. . Similarly calculate the absolute and relative errors associated with the backward recurrence relation and store them in arrays abserr2 and relerr2 respectively. Also provide one plot showing the relationship between k and the relative error arrays you get from both schema. Note: In both the calculations above, use the values generated by the function func_int to be the true values. Inputs: nmax: The upper bound of k value func_int: A function that takes an input k, and returns the exact integral IX Outputs: I1: [11, 12, 13,..., Inmar) calculated using the forward recurrence relation 12:[11, 12, 13,...,Inmar) calculated using the backward recurrence relation abserri and relerri: Absolute and Relative error associated with the forward recurrence relation abserre and relerr2: Absolute and Relative error associated with the backward recurrence relation Plot: As described above with relevant title, labels etc. Note: please exclude Io in both 11 and 12 The setup code gives the following variables: Name Type nmax int func int function Description The upper bound of k value A function that takes an input k, and returns the exact integral Ile Your code snippet should define the following variables: Name Type Description 11 array 11, 12, 13,...,Inmar] calculated using the forward recurrence relation 12 array [11, 12, 13,...,Inmar] calculated using the backward recurrence relation abserri array Absolute error associated with the forward recurrence relation relerri jarray Relative error associated with the forward recurrence relation abserr2 Jarray Absolute error associated with the backward recurrence relation relerr2 Jarray Relative error associated with the backward recurrence relation In this problem we will use recurrence relations to compute an integral and determine the relative and absolute error associated with each of them. As an aside (not required) you should be able to verify both the recurrence relation on your own. Now, consider the integral Ik = 1 ze" da where lo =1-1/e Evaluate the integrals In and store them in an array, 11, using the 'Forward Recurrence Relation' defined as follows: Ix=1-klx-1 ke 1, 2, 3, ....., nmax We would now use a 'Backward Recurrence Relation' to determine the integrals. Assume that Ik = 0 for k = nmax. Using this and the recurrence relation provided below, evaluate the integrals and store them in an array named 12: Ix-1= (7 ) ke nmax, ........., 1 Now let us evaluate the error associated with both the schemes. Calculate the exact integral using the provided function func_int which takes the input k and returns the integral IR. Calculate the integral for all the k values in the array [1, 2, 3,..., nmax). Calculate the absolute and relative errors associated with the forward recurrence relation and store them in arrays abserri and relerri respectively. . Similarly calculate the absolute and relative errors associated with the backward recurrence relation and store them in arrays abserr2 and relerr2 respectively. Also provide one plot showing the relationship between k and the relative error arrays you get from both schema. Note: In both the calculations above, use the values generated by the function func_int to be the true values. Inputs: nmax: The upper bound of k value func_int: A function that takes an input k, and returns the exact integral IX Outputs: I1: [11, 12, 13,..., Inmar) calculated using the forward recurrence relation 12:[11, 12, 13,...,Inmar) calculated using the backward recurrence relation abserri and relerri: Absolute and Relative error associated with the forward recurrence relation abserre and relerr2: Absolute and Relative error associated with the backward recurrence relation Plot: As described above with relevant title, labels etc. Note: please exclude Io in both 11 and 12 The setup code gives the following variables: Name Type nmax int func int function Description The upper bound of k value A function that takes an input k, and returns the exact integral Ile Your code snippet should define the following variables: Name Type Description 11 array 11, 12, 13,...,Inmar] calculated using the forward recurrence relation 12 array [11, 12, 13,...,Inmar] calculated using the backward recurrence relation abserri array Absolute error associated with the forward recurrence relation relerri jarray Relative error associated with the forward recurrence relation abserr2 Jarray Absolute error associated with the backward recurrence relation relerr2 Jarray Relative error associated with the backward recurrence relationStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started