Error using sum Invalid data type. First argument must be numeric or logical.
Afficher commentaires plus anciens
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?
Réponses (1)
Walter Roberson
le 18 Juin 2018
R=@(q) sum(fun2(q));
5 commentaires
Yuriy Yerin
le 19 Juin 2018
Guillaume
le 19 Juin 2018
But after this correction I still have the same error
Very doubtful. You may get an error but it shouldn't be the exact same error. What is the error you now get?
Yuriy Yerin
le 19 Juin 2018
Guillaume
le 19 Juin 2018
fun2 = @(q) k*w*gamma0(q)./q.^3;
possibly, assuming gamma0 is supposed to use q as input.
Steven Lord
le 19 Juin 2018
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
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!