how do make the integral a vector

21 ビュー (過去 30 日間)
Daniel Thomas
Daniel Thomas 2018 年 11 月 14 日
編集済み: Daniel Thomas 2018 年 11 月 14 日
integral = 0
for i = 1:n
r_left = (a+(i-1)*h);
r_right = (a+i*h);
% Functions
f_left = f(r_left);
f_right = f(r_right);
% Integral
integral = integral+(h/2)*(f_left+f_right)
end
  1 件のコメント
madhan ravi
madhan ravi 2018 年 11 月 14 日
completely vague

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

回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 14 日
編集済み: madhan ravi 2018 年 11 月 14 日
integral=cell(1,n);
integral{1}=0;
for i = 2:n
r_left = (a+(i-1)*h);
r_right = (a+i*h);
% Functions
f_left = f(r_left);
f_right = f(r_right);
% Integral
integral{i} = integral{i-1}+(h/2)*(f_left+f_right) %put {i} next to integral to avoid overwriting
end
celldisp(integral) %to view values
integral = cell2mat(integral) %to convert to double array

カテゴリ

Help Center および File ExchangeModify Image Colors についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by