I need help getting the trapezoidal rule to work for my integration?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!