我在 Matlab 中编写了一个程序,目的是计算某个函数的积分。我应该使用梯形法进行积分。目前,代码如下所示:
a=0; b=2.5; n=2; % n is the number of intervals
h=(b-a)/n; %the width of every interval
x=a:h:b
y=labb2uppg1Funkfil(x)
trapets=h*(sum(y)-(y(1)+y(length(y)))/2)
plot(x,y)
% This is located in a different file named labb2uppg1Funkfil
function y = funk(x)
y = exp(-x/3)/(2-cos(pi*x));
我认为问题在于我的函数只返回一个 y 值,而它应该更多!如何重写函数以返回多个值?还是这里有其他问题?
提前致谢!结尾