How can I use the command "Y = integral(function, x_min, x_max)" properly?

조회 수: 2 (최근 30일)
Christoph
Christoph 2014년 7월 17일
답변: Christoph 2014년 7월 17일
Hey there,
within some calculations I tried integrating an equation using the "integral" command.
Unfortunately this did not work out as I hoped it would!
Would be great if someone here can help me and show me what I made wrong or teach me a better more accurate way to solve the integral.
Thanks a lot and good luck for what ever you try to calculate...
________________
the code:
A = 2548.9320;
B = 3.5248;
C = -0.6366;
D = -3.4281;
E = 49.8238;
F = -120.3466;
G = 98.8658;
M = 28.9586;
t_1 = 290.;
t_2 = 545.;
fun = @(T) (B + (C-B) * (T/(A+T))^2 * ( 1 - (A/(A+T)) * ( D + E * (T/(A+T)) + F * (T/(A+T))^2 + G * (T/(A+T))^3) ))*R/T;
cp = integral(fun, t_1, t_2);

채택된 답변

Sean de Wolski
Sean de Wolski 2014년 7월 17일
편집: Sean de Wolski 2014년 7월 17일
First, you're missing R so you'll need to define it. (I defined it as 1 to get it to solve).
The problem is that your function is doing matrix multiplication and division and integral will call it with vectors not just scalars. You want the operations to work elementwise so you'll need to add a '.' before some of them (like /^*). Fortunately there's a convenience function called vectorize to do this for you:
vectorize '@(T) (B + (C-B) * (T/(A+T))^2 * ( 1 - (A/(A+T)) * ( D + E * (T/(A+T)) + F * (T/(A+T))^2 + G * (T/(A+T))^3) ))*R/T;'
ans =
@(T) (B + (C-B) .* (T./(A+T)).^2 .* ( 1 - (A./(A+T)) .* ( D + E .* (T./(A+T)) + F .* (T./(A+T)).^2 + G .* (T./(A+T)).^3) )).*R./T;
Now paste that in as your fun (and define R!) and it will solve:
fun = @(T) (B + (C-B) .* (T./(A+T)).^2 .* ( 1 - (A./(A+T)) .* ( D + E .* (T./(A+T)) + F .* (T./(A+T)).^2 + G .* (T./(A+T)).^3) )).*R./T;
cp = integral(fun, t_1, t_2)

추가 답변 (1개)

Christoph
Christoph 2014년 7월 17일
Hey Sean,
thank you very much for the fast answer!
You helped me a lot!
__________________
ps: nice dogs!

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by