MATLAB Answers

1

error using trapz function

Asked by mitis myosotis on 15 May 2019
Latest activity Commented on by mitis myosotis on 15 May 2019
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)

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 15 May 2019

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?

  1 Comment

You are right, integralm is a value.. I tried to write the function of delta m there. Integralm is my value that i got from the integral function. In delta m's function, there is an integration. Do i really have to take the integration of delta m by hand? It becomes so long..

Sign in to comment.