// //Prelab4_2.sce // //This program will use trapezoind rule to approximate the //integral of a function. // //By: M. Coburn, J. Wireman // //Defintion of the function to be integrated function foo = f(x) foo = 5*x + sin(9*x - 5)/x endfunction //Set the time length and step size t_start = 1; t_end = 9; subs = 1000; delta_x = (t_end - t_start)/subs; //This loop uses the trapezoid rule to approximate the integral of the function //on the interval defined above. total = 0; for i = 0:subs, x = t_start + i*delta_x; if i == 0 then total = total + f(x); elseif i == subs then total = total + f(x); else total = total + 2*f(x); end end total = total * delta_x/2; printf("The approximate value of the integral is %f\n", total);