On using Trapz for a function defined by a variable using syms

clear
g = 1;
k = 0.2;
no = 0;
nm = 0;
D = 1;
O = -1;
gam = 0.2;
syms w
xa = -1i.*(w+D)+(k./2);
xb = -1i.*(w-O)+ (gam./2);
xac = conj(xa);
xbc = conj(xb);
c = (1i.*g.*sqrt(k))./(xa.*xb + g.^2);
d = (xa.*sqrt(gam))./(xa.*xb + g.^2);
f(w) = (abs(c).^2).*(no+(1/2))+(abs(d).^2).*(nm+(1/2));
df = diff(f,w);
R = -999:999;
%Q = trapz(R,f(w));
fplot(f(w))
set(gca,'FontSize',14)
title('g = 1, \Delta = 1')
xlabel('\omega')
ylabel('S_{bb}')
Greetings!
I am trying to find the area under a power spectrum. All seems to be well when it comes to plotting it, however as I try to use the Trapz() function, it is giving me the error: Input arguments must be convertible to floating-point numbers. Now I have tried searching for a solution online for a while but I still couldn't solve it. Would appreciate any help possible!
Thank you very much in advance!

 Risposta accettata

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by