How to write Matlab code based on the Simpson’s 1/3 rule?

14 ビュー (過去 30 日間)
Jason Nguyen
Jason Nguyen 2020 年 5 月 25 日
回答済み: Vemula Ramakrishna Reddy 2021 年 4 月 10 日
How to write Matlab code based on the Simpson’s 1/3 rule to integrate the function from the data?
This is what I have so far but Im getting an error :(
func_vec = [1.5 2 2 1.6363 1.2500 0.9565];
a = 0;
b = 2.5;
n = length(func_vec)-1;
h = (b-a)/n;
xi = a:h:b;
f_1sets = sum(func_data(2:2:end));
f_2sets = sum(func_data(3:2:end-2));
I = h/3*(func_vec(1) + 4*f_1sets + 2*f_2sets + func_vec(end));
  1 件のコメント
HImANSHU GANGWAR
HImANSHU GANGWAR 2020 年 10 月 31 日
please correct in -> f_1sets=sum(func_data(2:2:end-1)

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

回答 (2 件)

Vemula Ramakrishna Reddy
Vemula Ramakrishna Reddy 2021 年 4 月 10 日
The error is func_data should be func_vec
since you defined func_vec but not the func_data in your code.

Steven Lord
Steven Lord 2020 年 5 月 25 日
When you ask for help understanding / correcting an error, please include the full and exact text of that error message (all the text displayed in red in the Command Window) to make it easier for us to understand the problem you're experiencing. Please add a comment (either on the original question or on this answer) with that information.
Nowhere in your code does a variable or function named func_data appear. Can you also include the definition of that variable or function in your comment?

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by