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 CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by