How to take an integral symbolically and then convert it to type double?

How do I take the following integral symbolically? And convert it to double? I have a 1000 x 1 numeric vector of type double for A(t).
The following takes a minute or two to run and I'm not sure how to plot it to check.
syms t omega real
int(A*sin(omega*t),0,2*pi/omega)

6 comentarios

Since you have vector A as type numeric, the resulting integral for the expression sin(omega*t) between the limits 0 and (2*pi / omega) will always be zero.
I guess it's not possible to convert A to symbolic and then do the calculation?
VBBV
VBBV el 16 de Mayo de 2023
Editada: VBBV el 16 de Mayo de 2023
Its possible, but integral would still remain as zeros due to the expression inside the integral and the limits used for integration, since the values for integral using upper limit and lower limits cancel out
syms t omega real
A = rand(5,1);
Asym = sym(A);
int(Asym*sin(omega*t),0,2*pi/omega)
ans = 
Symbolic integration but the result is exactly 0 anyhow.
Note that the A* part is a constant compared to t or any function of t, so the A* can be moved outside the integration, making it A*int(sin(omega*t),0,2*pi/omega) . But the integral of that sine epression is 0
syms tau;
int(sin(tau*t), 0, 2*pi/omega)
ans = 
when tau = omega then that is sin(pi*1) which is 0.
Thank you. I think the symbolic aspect is confusing me, so I am trying to do it in a more straightforward numerical approach.
format long g
syms t omega real
A = rand(5,1)
A = 5×1
0.988717788679954 0.961075790428598 0.548371988302065 0.728110260321502 0.293761135174945
Asym = sym(A);
symbolic_result = int(Asym*sin(omega*t),0,2*pi/omega)
symbolic_result = 
omega = abs(randn())
omega =
1.29628039951883
numeric_result = integral(@(t) A .* sin(omega.*t), 0, 2*pi./omega, 'Arrayvalued', true)
numeric_result = 5×1
1.0e+00 * -2.20309881449055e-16 4.33680868994202e-17 -5.55111512312578e-17 -2.91433543964104e-16 -6.11490025281825e-17
Zero to within round-off error.

Iniciar sesión para comentar.

 Respuesta aceptada

VBBV
VBBV el 16 de Mayo de 2023
Editada: VBBV el 16 de Mayo de 2023
syms t omega real
A = rand(1000,1);
% specify the integration variable t as the argument
I = double(vpa(int(A.*sin(omega*t),t,0,2*pi/omega),2))
I = 1000×1
0 0 0 0 0 0 0 0 0 0

1 comentario

Assuming some random data, you can specify the integration variable t as the argument and do symbolic integration

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021b

Preguntada:

el 16 de Mayo de 2023

Comentada:

el 16 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by