フィルターのクリア

How to plot graph of Simpson's rule and Trapezoidal rule between error and n?

1 回表示 (過去 30 日間)
Nobita Nobi
Nobita Nobi 2020 年 12 月 12 日
回答済み: skerdi hymeraj 2021 年 10 月 3 日
Hi there,
I have written 2 programs of Simpson's rule and Trapezoidal rule to compute the integral of a function f. Now I would like to plot graphs of both rules between the errors and n but I don't know how to do it. Could anyone help me with this problem please?
Here is the code of my program:
a=0.1;
b=0.2;
n=30;
x=linspace(a,b,n);
h=(b-a)/n;
f=inline('x.^4-x.*5+1');
y=x.^4-x.*5+1;
H=h*ones(1,n); %trapezoid
H([1,n])=h/2;
tr=sum (H.*f(x));
tr
H(1:2:n)=2*h/3; %simpson
H(2:2:n)=4*h/3;
H([1,n])=h/3;
simp=sum(H.*f(x));
simp
Thank you in advance!

回答 (2 件)

Alan Stevens
Alan Stevens 2020 年 12 月 13 日
If you use cumsum instead of just sum then you can plot tr and simp against x.

skerdi hymeraj
skerdi hymeraj 2021 年 10 月 3 日
where is ploting

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by