I get error using plot, vectors must be same lengths and error in midpt (line 27), plot (x,If)? Integral code works fine, was just trying to plot a graph too..
Show older comments
Here's my code:
function [ area ] = midpt ( f,xl,xu,dx )
%area will be total area under integration curve
%using midpoint rule
%will also plot function and integral curves
%f is the function to integrate
%xl is the lower limit of integration
%xu is the upper limit of integration
num=(xu-xl)/dx;
a=xl;
x=xl:dx:xu;
M=0;
If=0;
for ii=1:1:num
b=a+dx;
M(ii)=(b-a)*f((a+b)/2);
If(ii)=sum(M);
a=b;
end
plot(x,If)
area=sum(M);
end
Accepted Answer
More Answers (0)
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!