Question: T'his homework is basically a mashup of these two studio questions: you should create a main program that computes an approximation to the integral f(z)dr
T'his homework is basically a mashup of these two studio questions: you should create a main program that computes an approximation to the integral f(z)dr where the (math) function f(a) is defined in a C++function whose prototype is float myfcn(float); The key part here is that f(z) should be implemented only in the C++ function myfcn. You wil have done things correctly if you can first make nyfcn implement f(x) cos(for which the exact integral is 2 sin(1) 1.68294 ), and then change to f(x)-14 + 2x (exact integral 0.4) by changing only the code inside myf cn (and nowhere else!) Just like in studio, we will approximate the integral by dividing the z axis into a number of segments, approximating the area of each segment assuming it's a trapezoid i.e., assuming that the function varies linearly 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/N apart You wil 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
