how do I store the value of integrals of function k for all values of T for the below code??

1 visualización (últimos 30 días)
T=[0:20:1000];
k=@(x)((x.^2).*exp((4*x)/3))./((exp(x)-1).^2)
q=integral(k,0,-td./T)
I'm getting the following error:
Error using integral (line 85)
A and B must be floating-point scalars.
Error in hw4 (line 12)
q=integral(k,0,-td./T)
T is an array ,k is a function, td is constant
  1 comentario
Torsten
Torsten el 6 de Nov. de 2017
Is td positive or negative ?
First remove the singularity of your function ; you divide by 0 at x=0.
Best wishes
Torsten.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Nov. de 2017
You could do
q = arrayfun(@(endpoint) integral(k,0,endpoint), -td./T)
However, this would require that the integration over each segment be done multiple times. It would be more efficient to do something like
endpoints = [0, -td./T(:).'];
qt = arrayfun(@(IDX) integral(k,endpoints(IDX),endpoints(IDX+1)), 1:length(endpoints)-1);
q = cumsum(qt);
  4 comentarios
Walter Roberson
Walter Roberson el 6 de Nov. de 2017
What is class(td) ? Is it double, or is possible it is integer data type? Is td positive or negative?
I notice that you start T at 0 and your endpoints are -td./T which implies that your first endpoint is either -inf or +inf. I did not break up the endpoints the right way for that case; the proper break-up will depend upon whether td is positive or negative.

Iniciar sesión para comentar.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by