在Matlab中计算函数的面积

时间:2016-11-09 01:36:48

标签: matlab error-handling

close all, clear *, clc

% load('dataset1.mat');
% plot(x,y, '-'), hold on

load('dataset2.mat');
plot(x,y, '-'), hold on

fi=y;
n=length(x);

result = 0;

for j =1:n
I=simpsons(fi,x(1),x(n),[]);
result=result+I;
end

o = 1;
disp('Ergebnis:' + o); % had before this: disp('Ergebnis:' + result); 
                    % but also that didnt work and I got these weird
                    % numbers

使用simpson方法我想计算这个图的面积但它不起作用我在命令窗口中得到了数字

enter image description here

function I = simpsons(f,a,b,n)
n=numel(f)-1; 
h=(b-a)/n;
I= h/3*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end))+f(end));
end

0 个答案:

没有答案