I need help getting the trapezoidal rule to work for my integration?

조회 수: 1 (최근 30일)
Garrett
Garrett 2014년 12월 1일
I am trying to write a script that will evaluate the integral of x*e^(2*x)dx with limits of 0 and 1. So far I have written the following loop:
clear all
u=[0:0.25:1]; v=[0:0.1:1]; w=[0 1]; x=[0 1];
w=0; x1=linspace(0,1,135); myintegral=@(x) x.*exp(2.*x); while (1) w=w+1 h=(1/w) x1=0:h:1; x2=h:h-1:h; skunkworks=sum(myintegral(x2)); lockheed=(h/2)*(myintegral(0)-myintegral(1)); nasa=sum(skunkworks+lockheed); grumman=integral(myintegral,0,1); wrightbros=abs((grumman-nasa)/grumman)*100; if wrightbros<=0.01,break,end; end
(with the vectors being initialized for plotting after I have evaluated the integral). But For some reason I cannot get this code to work, as it goes on and on forever on the command window and gives me a different error each time I try to run the code.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by