How do I use the integral function with an m-file that contains a for loop? Integral Function Problems

3 views (last 30 days)
Hi, I am trying to integrate the following function with respect to T :
Cp= A0 + (A1*T^1) + (A2*T^2) + (A3*T^3) + (A4*T^4) + (A5*T^5) + (A6*T^6) + (A7*T^7) + (A8*T^8)
so that:
h=integral of Cp from Tz=.005 to Tz=.373
I have written an m file to define Cp, but when I use the integral function to call my .m file, I get a value that is way lower than what it should be. The value of the integral comes back less than 1 when it really should be about 341.2. I am including my .m file code and how I tried to use the integral below. Any pointers would be very appreciated. Thank you in advance.
(note: T in the equation for Cp is actually a value Tz where Tz=T/1000)
Parameters:
Ts= 373.15; %INPUT = DEGREES IN KELVIN
Tz=Ts/1000;
MW_o2 = 31.999;
R_o2=.260;
T_ref_K= 0.5; % KELVIN, temp is NOT CELSIUS
T_ref_C= -272.65;
P_ref=101; % kPa
matrix_o2 = [ 1.00645, -1.047869, 3.729558, -4.934172, 3.284147, -1.095203, 0.145737, 0 ,0, 0.36979, 0.000491 ];
Tz_low=.5/1000;
Tz_high=Ts/1000
Cp_o2_old=0; %this would be a function INPUT
m-file
function [ y ] = Cp_o2( Cp_o2_old, matrix_o2, Tz )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
for i=1:9
value_o2=matrix_o2(i)*(Tz.^(i-1))
Cp_o2_new=Cp_o2_old + value_o2
Cp_o2_old=Cp_o2_new;
Cp_o2_new;
end
y=Cp_o2_new;
end
integral function:
integral(@(Tz)Cp_02(Cp_o2_old, matrix_o2, Tz), Tz_low, Tz_high)
Thank You Again, J. Ryan Kersh

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!