Mid point value of a function

I need to find the sum with value of T at mid of every subinteval
for j= 1:1:n+1
Rsum2=Rsum2+bb(j+1)*T(j+1/2)
end
but get an error
"Array indices must be positive integers or logical values."
How can I find value of T at midpoint of every interval in this loop?

3 件のコメント

David Hill
David Hill 2021 年 2 月 5 日
Your question is confusing, what is bb and T? Provide a simple example of what you want for your output.
Mubashara Wali
Mubashara Wali 2021 年 2 月 7 日
Leave bb. Its just a coefficient. T is a function. Suppose my interval is [0,1] with n subintervals and I need to find the sum of the function at midpoint of every subinterval.
Mubashara Wali
Mubashara Wali 2021 年 2 月 7 日
How can I find this sum in a loop?

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

回答 (2 件)

Jan
Jan 2021 年 2 月 5 日

0 投票

T(j+1/2) is not valid, when T is a vector. You need integer values as indices.
Perhaps you mean:
(T(j) + T(j+1)) / 2
Jan
Jan 2021 年 2 月 7 日

0 投票

interval is [0,1] with n subintervals and I need to find the sum of the function at midpoint of every subinterval.
n = 27;
interval = linspace(0, 1, n);
% If T is vectorized:
Result = sum(T(interval(1:n-1) + interval(2:n)) / 2)
% If T works for scalars only:
Result = 0;
for k = 1:n-1
Result = Result + T(0.5* (interval(k) + interval(k+1)));
end

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2021 年 2 月 5 日

回答済み:

Jan
2021 年 2 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by