Filter löschen
Filter löschen

Numerical integral where the bounds change with each evaluation

13 Ansichten (letzte 30 Tage)
L'O.G.
L'O.G. am 16 Mai 2023
Kommentiert: Walter Roberson am 16 Mai 2023
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 Kommentare
FannoFlow
FannoFlow am 16 Mai 2023
Does A(t) have a special meaning in this context?
Walter Roberson
Walter Roberson am 16 Mai 2023
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Mai 2023
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 Kommentare
Walter Roberson
Walter Roberson am 16 Mai 2023
"how would you modify it to use a vector of type double which is also a function of t"
Vectors are not functions.
If you have the value of A(t) sampled at particular t, then calculate A(t).*sin(omega*t) at those t, and use trapz() or similar to do numeric integration, making sure to pass in the appropriate t values to trapz()
Walter Roberson
Walter Roberson am 16 Mai 2023
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 ?

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by