i need to count with Simpson's Rule s but some where i have mistake....
>> f=@(x)(exp(x).*sqrt(1+sin((pi.*x)./2))); %Change here for different function
a=-1;b=3; %Given limits
n=6; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=(exp(i).*sqrt(1+sin((pi.*i)./2))); %Change here for different function
end
l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+4*(y(3)+y(5))+(y(2)+y(4)+y(6)))
pls help my to find mistake

1 件のコメント

Are Mjaavatten
Are Mjaavatten 2018 年 3 月 15 日
Your x vector should be:
x = a:h:b;
and since you have already correctly defined f, y is simply:
y = f(x);
Then take a closer look at your Simpson formula.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2018 年 3 月 14 日

コメント済み:

2018 年 3 月 15 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by