Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Matlab function m-file (i.e., the first statement in the m-file must be

ID: 3821569 • Letter: C

Question

Create a Matlab function m-file (i.e., the first statement in the m-file must be the word function) that satisfies the following: is named simp13.m returns all results to the display in long format If a user inputs into the Matlab display (prior to calling simp13) only a single vector, y, representing values of the dependent variable, upon typing >>simpl3 (y) then pressing Enter on the keyboard simp13(y) computes an approximation of the integral of vector y via Simpson's 1/3 rule (with unit spacing). Since unit spacing is assumed, to compute the integral for spacing different from one (which must be the same throughout the integration interval), the user must manually i.e., using a calculator, multiply the answer returned by simp13(y) by the actual spacing increment. If a user inputs into the Matlab display (prior to calling simp13) only a matrix, y, representing values (rows) of different dependent variables (columns), upon typing >>simp13 (y) then pressing Enter on the keyboard simp13(y) returns a row vector with each element equal to an approximation of the integral over each column of y via Simpson's 1/3 rule (with unit spacing). Since unit spacing is assumed, to compute the integral for spacing different from one (which must be the same throughout the integration interval), the user must manually, i.e., using a calculator, multiply the answers returned by simp13(y) by the actual spacing increment. In all cases where no independent variable vector is entered, the following statement should display to the Matlab display, If a user inputs into the Matlab display (prior to calling simp13) a single vector x, representing values of the independent variable, and a single vector y, representing values of the dependent variable, upon typing >> simp13 (x, y) then pressing Enter on the keyboard simp13 (x, y) computes the integral of y with respect to x using Simpson's 1/3 rule. If the user inputs an independent vector x and dependent vector (or matrix) y, that are not of the same length, Matlab displays to the Matlab display an error statement and the following statement, Input vector arguments must be of the same length. Note that two additional requirements are the number of rows of the input vectors must be odd (so that the # of intervals is even) and the increment of x must be the same throughout the integration interval. If the user input results in an odd # of intervals, Matlab displays to the Matlab display an error statement and the following statement, Odd # of intervals If the user input results in two sequential intervals of different length, Matlab displays to the Matlab display an error statement and the following statement, Two sequential intervals are not equal.

Explanation / Answer

x = -2:.2:2; y = -2:.25:2; z = -2:.16:2; [x,y,z] = meshgrid(x,y,z); v = x.*exp(-x.^2-y.^2-z.^2); xslice = [-1.2,.8,2]; % location of y-z planes yslice = 2; % location of x-z plane zslice = [-2,0]; % location of x-y planes slice(x,y,z,v,xslice,yslice,zslice) xlabel('x') ylabel('y') zlabel('z')