フィルターのクリア

Error using sum Invalid data type. First argument must be numeric or logical.

2 ビュー (過去 30 日間)
Yuriy Yerin
Yuriy Yerin 2018 年 6 月 18 日
コメント済み: Steven Lord 2018 年 6 月 19 日
Hi everybody.
I try to make integration over the variable q for the expression with inside integration and summation and find the answer in the form of the numerical value. Here my simple code
function z=self_energy_summation
k=1;
w=10;
z1=load('test.txt');
tt=z1(741,1);
T_c=z1(741,2);
mu=z1(741,3);
N=1:10;
nn=10^4;
fun1=@(a,q) a.*tanh((a.^2-mu)./(2*T_c)).*log((2*a.^2+2*a.*q+q.^2-2*mu-1i*2*pi.*N(1:10).*T_c)./(2*a.^2-2*a.*q+q.^2-2*mu-1i*2*pi.*N(1:10).*T_c))./q-2;
Gamma0=@(q) tt+integral(@(a)fun1(a,q),0,nn,'ArrayValued',true);
fun2=@(q) k*w*Gamma0./q.^3;
R=@(q) sum(fun2);
y=integral(@(q) R(q),0.001,nn,'ArrayValued',true)
end
Before the last integration I get the error
"Error using sum Invalid data type. First argument must be numeric or logical."
If I execute my script without last integration then the program works correctly.
Could you help me?

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 6 月 18 日
R=@(q) sum(fun2(q));
  5 件のコメント
Guillaume
Guillaume 2018 年 6 月 19 日
fun2 = @(q) k*w*gamma0(q)./q.^3;
possibly, assuming gamma0 is supposed to use q as input.
Steven Lord
Steven Lord 2018 年 6 月 19 日
You cannot perform arithmetic operations on function handles, nor can you sum them. Instead perform arithmetic or call sum on the values returned by evaluating the function handle.
f = @(x) x.^2;
g1 = 2*f(1:10) % works
g2 = 2*f % does not work

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

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by