how do I store the value of integrals of function k for all values of T for the below code??
1 view (last 30 days)
Show older comments
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 Comment
Torsten
on 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.
Answers (1)
Walter Roberson
on 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 Comments
Walter Roberson
on 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.
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!