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

1 vue (au cours des 30 derniers jours)
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 commentaire
Torsten
Torsten le 6 Nov 2017
Is td positive or negative ?
First remove the singularity of your function ; you divide by 0 at x=0.
Best wishes
Torsten.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 5 Nov 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 commentaires
Aqeel Mohammed Abdul Mageeth
td is a constant with given value and T is an array [1:20:1001]
Walter Roberson
Walter Roberson le 6 Nov 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by