function [I] = simp38int( h , fx )% this function takes data sampled at evenly spaced locations as inputs and
%returns an approximation of the integral over the sample range based on
%Simpson?s multiple-application 3/8 rule
% Inputs:
% h : (scalar) step size seperating adjacent sampling locations
% fx: (N-element vector) function data taken at uniform locations sperated
% by a distance h
% Outputs
% I: approximation for the integral of fx for the sampled range
%Step one: check for error
N = length(fx); %getting length of fx for error check
%checking that h is a scalar
if isscalar(h) == 0 error('h is not a scalar')end%checking that fx is a vector then checking that it is an odd vector
if isvector(fx)==0 error('fx is not a vector')%checking that h and fx both contain all numerical values
if isnumeric(h) == 0 error('h is not numerical')elseif any(isnumeric(fx(:))) ==0 error('fx contains non numerical values')endsum3 =0sum2 = 0%implementing solving algorithm
for i = 2:3:N-1 sum3 = sum3 + 3*(fx(i)+fx(i+1)) endfor i = 4:3:N-2 z2= sum2+2*fx(i)endI = 3*h/8*(fx(1)+sum3+sum2+fx(N))end
MATLAB: Does it keep saying that the output variable I is not assigned? It also says there are not enough input arguements for N = length(fx)
function errorinput arguementsintegrationoutputoutput errorsim83
Best Answer