can i integrate this function using integral?
15 次查看(过去 30 天)
显示 更早的评论
I tried to integrate a function using the integral command but it did not work. I also used trapz but I think i'm missing some key information.
I have a function as follows:
f(t) = from 0 to t sin(2*pi*x)e^-x dx
here is the code i have so far. i know it's wrong but i am not sure what to do :(
i was also given range of t from 0 to 10 having 100 points.
clc; clear all; close all;
t = 1:.001:10;
f= sin(2*pi.*t).*exp(-t);
plot(f)
Z=trapz(t)
0 个评论
回答(2 个)
Roger Stafford
2014-10-31
You haven't shown us your code for using the 'integral' function, but your code for using 'trapz' has the right integrand function but the wrong limits of integration. These go from 1 to 10, not from 0 to a variable t, and involve 9001 points, not 100.
For the purpose of computing a function f(t) to express the integral from 0 to a variable t, it is infinitely preferable to use the known explicit solution for this integral.
As can be determined by looking in a good table of integrals or using the Symbolic Toobox function 'int' its indefinite integral is:
-exp(-x)/(1+4*pi^2)*(sin(2*pi*x)+2*pi*cos(2*pi*x)
so the definite integral from 0 to t would be
(2*pi-exp(-t)*(sin(2*pi*t)+2*pi*cos(2*pi*t)))/(1+4*pi^2)
0 个评论
Star Strider
2014-10-31
You need to code ‘f’ as an anonymous funciton to use it with integral:
f= @(x) sin(2*pi.*x).*exp(-x);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!