MATLAB: Using for loop plotting problem help me

for loopMATLABplotting

function homework
f= @(x) 3*x^5+7*sind(x)^2;
fd= @(x) 15*x^4+7*sind(2*x)^2+3*x^5+7*sind(x)^2;
a=-1;
b=3;
n=5;
e=1.1*10^3;
s=(fd(a)+fd(b));
for i=1:1:n-1
h=(b-a)/i;
s=s+2*fd(i);
I=(h/2).*s
error=I-e
end
end
the problem is ı have values but try everything for plotting but see nothing even there is no line or spline .

Best Answer

hello
I assumed that you wanted to plot I and error , but you forgot to index thos variables
see below :
f= @(x) 3*x^5+7*sind(x)^2;
fd= @(x) 15*x^4+7*sind(2*x)^2+3*x^5+7*sind(x)^2;
a=-1;
b=3;
n=5;
e=1.1*10^3;
s=(fd(a)+fd(b));
for i=1:1:n-1
h=(b-a)/i;
s=s+2*fd(i);
I(i)=(h/2).*s;
error(i)=I(i)-e;
end
figure(1),plot(1:n-1,I,'b')
figure(2),plot(1:n-1,error,'r')