trapz or integral which one is more accurate?

3 ビュー (過去 30 日間)
masoud avaznejad
masoud avaznejad 2020 年 8 月 23 日
回答済み: Alan Stevens 2020 年 8 月 23 日
clc
clear
close all
x = linspace(0,100);
y = x.^cos(x);
plot(x,y);
a = trapz(x,y);
y = @(x)x.^cos(x);
b = integral(y,0,100);
c=a-b;

採用された回答

Alan Stevens
Alan Stevens 2020 年 8 月 23 日
integral is more accurate here. Try
x = linspace(0,100,1000);
and you will find the trapz result reduces to get much closer to the integral result.

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by