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..
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Exploration and Visualization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!