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 Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by