How can I use the command "Y = integral(function, x_min, x_max)" properly?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Christoph
el 17 de Jul. de 2014
Respondida: Christoph
el 17 de Jul. de 2014
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);
0 comentarios
Respuesta aceptada
Sean de Wolski
el 17 de Jul. de 2014
Editada: Sean de Wolski
el 17 de Jul. de 2014
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)
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Adding custom doc en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!