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

5 vues (au cours des 30 derniers jours)
Alvin
Alvin le 19 Juil 2017
Commenté : Alvin le 19 Juil 2017
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 19 Juil 2017
Q = trapz(R, f(R));
  1 commentaire
Alvin
Alvin le 19 Juil 2017
Good god am I an idiot. Thank you very much for the help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by