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

조회 수: 5 (최근 30일)
Alvin
Alvin 2017년 7월 19일
댓글: Alvin 2017년 7월 19일
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!

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 19일
Q = trapz(R, f(R));

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by