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

1 Ansicht (letzte 30 Tage)
Garrett
Garrett am 1 Dez. 2014
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.

Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by