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

2 ビュー (過去 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));
  1 件のコメント
Alvin
Alvin 2017 年 7 月 19 日
Good god am I an idiot. Thank you very much for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by