can i integrate this function using integral?

13 Ansichten (letzte 30 Tage)
Nicole
Nicole am 31 Okt. 2014
Beantwortet: Roger Stafford am 31 Okt. 2014
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)

Antworten (2)

Roger Stafford
Roger Stafford am 31 Okt. 2014
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)

Star Strider
Star Strider am 31 Okt. 2014
You need to code ‘f’ as an anonymous funciton to use it with integral:
f= @(x) sin(2*pi.*x).*exp(-x);

Community Treasure Hunt

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

Start Hunting!

Translated by