how do I store the value of integrals of function k for all values of T for the below code??
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Torsten
2017-11-6
Is td positive or negative ?
First remove the singularity of your function ; you divide by 0 at x=0.
Best wishes
Torsten.
回答(1 个)
Walter Roberson
2017-11-5
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 个评论
Walter Roberson
2017-11-6
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!