input argument q is undefined

function trapezoid(f,p,q,n)
h =(q-p)/n
sum = 0;
for i = 1:n-1
x = p+i*h;
sum = sum+ 2*f(x);
end;
total = (f(p)+f(q)+sum)*h/2;
fprintf('The value of integration is: %8.4f',total)

2 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 7 月 21 日
Steven Lord
Steven Lord 2018 年 7 月 21 日
Show/tell us how you call your trapezoid function.
FYI, you should avoid creating variables with the same name as functions in MATLAB. If later on you wanted to call the sum function inside the trapezoid function, you would not be able to do so, as the name sum refers to your variable.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFunction Creation についてさらに検索

質問済み:

2018 年 7 月 21 日

コメント済み:

2018 年 7 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by