error when i declare my simpson rule function, variable not used?

56 Views Asked by At

keep getting an error line 43, assignment to simpson not supported. variable has the same name as a local function.

Did i code this correctly if anyone on here is familiar with matlab/simpsons rule? line 43 is mu function line..


a=input("Enter value of a:");

b=input("Enter value of b:");

n=input("Enter value of n:");

x=linspace(a,b,n+1);

y=exp(-x.^2);


function [simpson] = simpson(x,y)

sum=0;

if mod(length(x)-1,2)==1

disp('Cannot run code.')

else

for i=2:length(x)-1

if mod(i,2)==0

sum=sum+2*y(i);

else

sum=sum+4*y(i);

end

end

end

sum=sum+y(1)+y(x(end));

simpson=sum;

end
0

There are 0 best solutions below