# Numerical integral where the bounds change with each evaluation

조회 수: 8 (최근 30일)
L'O.G. . 2023년 5월 16일
댓글: Walter Roberson . 2023년 5월 16일
I'm trying to take the following integral: I tried this symbolically, but I think that was throwing me off. I am attaching some numerical data for the function A(t) and the time vector. How would you do this numerically? I imagine it would be something like the following, but I can't quite get it to work.
omega = logspace(-1,1,1000);
fun = @(t,omega) A*sin(omega*t);
for i = 1:1000;
w=omega(i);
f(i) = integral(@(t) fun(t,w),0,2*pi/w);
end
##### 댓글 수: 3표시 이전 댓글 수: 2숨기기 이전 댓글 수: 2
Walter Roberson 2023년 5월 16일
A(t) just means that A is a function of t.
It is the expression for some kind of tranform of A(t), but I am not sure what the name of this transform is.

댓글을 달려면 로그인하십시오.

### 답변 (1개)

Walter Roberson 2023년 5월 16일
A = rand
A = 0.8252
omega = logspace(-1,1,1000);
fun = @(t,omega) A*sin(omega*t);
for i = 1:1000;
w=omega(i);
f(i) = integral(@(t) fun(t,w),0,2*pi/w);
end
plot(omega, f) All of the values are within round-off error of 0.
However... there is a difference between what your mathematical expression shows here, compared to the integral you were calculating there and here.
In previous discussion, A was a constant. In the expression here, A is a function of t. That makes a big difference.
For example,
A = @(t) t.^2 - t + 1;
omega = logspace(-1,1,1000);
fun = @(t,omega) A(t).*sin(omega*t);
for i = 1:1000;
w=omega(i);
FUN = @(t) fun(t,w);
f(i) = integral(FUN,0,2*pi/w);
end
plot(omega, f) syms t Omega
A = @(t) t.^2 - t + 1;
omega = logspace(-1,1,1000);
fun = @(t,omega) A(t).*sin(omega*t);
F = int(fun(t,Omega), t, 0, 2*pi/Omega)
F = f = subs(F, Omega, omega);
plot(omega, f) ##### 댓글 수: 4표시 이전 댓글 수: 3숨기기 이전 댓글 수: 3
Walter Roberson 2023년 5월 16일
Hmmm, first, could you confirm for me that you want omega to range from -1 to 1, and the bounds of integration is 0 to 2*pi/omega -- and since omega ranges from -1 to +1, that means that for negative omega you want negative upper bound, and you want to go right through to infinite upper bound as omega passes through 0 ?

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

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

Start Hunting!