I want to integrate a function
Mostrar comentarios más antiguos
i want to integrate this function used quad function but giving error
kindly resolve
2 comentarios
Walter Roberson
el 28 de Dic. de 2021
Your code is
function Ix = f(x)
global Lz cr2 n1 n2
%wq = x.*x *cr2/(2 * Lz*Lz);
wq = x;
f5 = fbjnn(x,n1,n2);
Ix = (x.^3).*f5;
end
We do not have values for those global variables, and we do not have your fbjnn function, so we are not able to test the code.
What error message is given?
Torsten
el 28 de Dic. de 2021
Can "fbjnn" handle vector inputs for x ?
Respuestas (5)
reshma nesargi
el 28 de Dic. de 2021
0 votos
reshma nesargi
el 28 de Dic. de 2021
0 votos
1 comentario
z and k are incompatible in size.
That's why I asked whether fbjnn can deal with vector input. This shows: it can't.
Use "integral" instead of "quad" and call it with the option 'ArrayValued',true :
Ix = quad('f',0,100); -> Ix = integral(@f,0,100,'ArrayValued',true);
Iz = quad('fun',0,100); -> Iz = integral(@fun,0,100,'ArrayValued',true);
reshma nesargi
el 28 de Dic. de 2021
0 votos
1 comentario
Walter Roberson
el 29 de Dic. de 2021
'ArrayValued',true is a "name/value pair" that should be written exactly as Torsten showed.
reshma nesargi
el 28 de Dic. de 2021
0 votos
Walter Roberson
el 29 de Dic. de 2021
global Lz cr2 n1 n2
Uh-oh... caution time.
Lz = 1*10^-06;
cr2 = (hc * c)/(ec * b);
Okay, the globals Lz and cr2 are defined.
for i = 0:1:20
t(i+1)=i;
bkt=kB*t(i+1);
Ix = integral(@f, 0, 100, 'arrayvalued', true)
Okay, what does f do?
function Ix = f(x)
global Lz cr2 n1 n2
%wq = x.*x *cr2/(2 * Lz*Lz);
wq = x;
f5 = fbjnn(x,n1,n2);
Ix = (x.^3).*f5;
end
... f uses the global variables n1 and n2 that are not defined.
3 comentarios
reshma nesargi
el 1 de En. de 2022
Walter Roberson
el 1 de En. de 2022
Show us the lines that assign values to n1 and n2 in Bulk.
reshma nesargi
el 2 de En. de 2022
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!