Problem with a program concerning composite trapezoid rule

12 ビュー (過去 30 日間)
Drake
Drake 2013 年 10 月 22 日
回答済み: sixwwwwww 2013 年 10 月 22 日
In this program I'm using the composite trapezoid rule on integral dx/(1+x^2) from 1 to 0. I've used the same program with different functions and haven't had issues till I tried it with this function. It says I have an error with line y=f(x); Here is code:
f = @(x) 1/(1+x^2);
a=0;
b=1;
n=100;
format long
h = (b-a)/n;
S = f(a);
i=1:1:n-1;
x=a+h*i;
y=f(x);
S=S+2*sum(y);
S=S+f(b);
F=h*S/2

採用された回答

sixwwwwww
sixwwwwww 2013 年 10 月 22 日
Dear Drake, re-write first line as:
f = @(x) 1./(1+x.^2);
then it should work. Good luck!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by