error using trapz function
古いコメントを表示
I have to calculate the amount of mass transported through a pipe in a given time range. delta m function is integration of density times flowrate from t1 to t2. First i tried to find the integral value with integral function. Then i tried to estimate the delta m with function trapz and using 24 segments. For 24 segments, i said from 1 to 7 , i have 24 segments if the stepsize is 0.25.
density=@(t) 4.*exp(-0.4.*t)+3.*exp(0.2.*t)
flowrate=@(t) 8+5.*((cos(0.38.*t)).^2)
t1=1
t2=7
deltam=@(t) (4.*exp(-0.4.*t)+3.*exp(0.2.*t)).*(8+5.*((cos(0.38.*t)).^2))
integralm=integral(deltam,t1,t2)
t=[1:0.25:7]
trapezm=trapz(t,integralm)
回答 (1 件)
Geoff Hayes
2019 年 5 月 15 日
mitis - is the error message
Subscript indices must either be real positive integers or logicals.
Error in ipermute (line 22)
inverseorder(order) = 1:numel(order); % Inverse permutation order
Error in trapz (line 72)
if ~isempty(perm), z = ipermute(z,perm); end
It may be because your second input parameter, which is a scalar, is being treated (by the function) as the dim input parameter. From dim input param, this parameter is a positive integer. In your code,
trapezm=trapz(t,integralm)
integralm is a double. Do you mean to pass this in as the dimension parameter? Or do you mean for it to represent something else?
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!