Integrating with a static starting value and changing end value

2 visualizaciones (últimos 30 días)
My code so far is:
Cp= @(T) 0.132+1.56e-4.*T+2.64e-7.*T.^2;
dT=linspace(0,300);
T0=-100;
dH=integral(Cp,T0,dT); %does not work yet
plot(dT,dH)
box on
I was wondering how I can make the integral work for this when T0 is a constant and dT isn't. I have tried using T0=-100*ones(size(dT));, but it didnt help

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 22 de Mayo de 2020
Either you'll have to simply loop:
Cp= @(T) 0.132+1.56e-4.*T+2.64e-7.*T.^2;
dT=linspace(0,300);
T0=-100;
for i_T = numel(dT):-1:1
dH(i_T)=integral(Cp,T0,dT(i_T)); %does not work yet
end
plot(dT,dH)
box on
or get an analytical solution of the integral (using the symbolic tools in matlab, by hand, or some other means (matematica, tables...)).
If trapz is a good enough way to approximate your integral you could use cumtrapz.
Just for a simple test I wrapped the integral function into a cumintegral function (since the loop recalculates the integrals over the same intervall multiple times I thought there would be some time to gain - but not more than a factor of ~1/2 in my test-case).
HTH

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by