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

1 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Matrix Computations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by