Question: ENME202/ENAE202 Computing Fundamentals for Engineers C+ Homework 4 In studio this week we wrote a C++ function that computed the approximate integral of a function

ENME202/ENAE202 Computing Fundamentals for Engineers C+ Homework 4 In studio this week we wrote a C++ function that computed the approximate integral of a function y( provided that we had two arrays containing a values and their corresponding y values. And, in a different question, we wrote a bisection method that found the root provided that we had a C++ function that computed the values f(x) for any given x value This homework is basically a mashup of these two studio questions: you should create a main program that computes an approximation to the integral (x)dr where the (math) function f(x) is defined in a C++ function whose prototype is float myfcn(float);. The key part here is that f(x) should be implemented only in the C++ function myfcn. You will have done things correctly if you can first make myfcn implement f(x) - cos(r) (for which the exact integral is 2sin(1) 1.68294), and then change to f()r4 + 2r (exact integral 0.4) by changing only the code inside myfcn (and nowhere, else!) Just like in studio, we will approximate the integral by dividing the x axis into a number of segments, approximating the area of each segment assuming it's a trapezod 1.e., assuming that the function varies learly within that segment), and then adding up the areas from all segments to get the total integral A new thing is that your program should now read in the number of segments N from the keyboard. This means that your points should be spaced a distance 2-2/N apart You will need to create an x array to hold these values. Make this array really long, say 1000 elements, to make sure you will never overrun it (i.e., your program will then work for N
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
