Function File to Solve Thermodynamics Problem

조회 수: 13 (최근 30일)
Joseph
Joseph 2011년 9월 28일
댓글: Walter Roberson 2020년 8월 5일
I am trying to solve a thermodynamics problem based on an isentropic relationship. The problem boils down to a higher order equation in terms of T2. Ultimately, T2 needs to be found. I would like to be able to write a function file that is a function of only T2 and then I can use bisection or newtons method to solve. I have input the isentropic relationship as my function, and the rest of my parameters under that. cp_2 and gamma2 are fucntions of T2. Right now, Matlab is not referencing the parameters under the isentropic relationship. Here is the code I have so far.
function [f]=temperature_2(T2)
f= T1*((.02*v1.^(gamma1-1))./(v1.^(gamma2-1)))-T2
%Givens
%Volume at state 1(cubic meters)
v1=.75
%Temperature at state 1(kelvin)
T1=375
%Universal gas constant(kJ/kmole)
R=8.314
%Matrix for a is given in the problem statement
a=[2.0909*10^1; 6.8717*10^-2; -5.2719*10^-5; 2.1664*10^-8; -4.5346*10^-12; 3.7873*10^-16];
%cp_1 calculation, there is enough info to compute this
cp_1=a(1)+T1.*(a(2)+T1.*(a(3)+T1.*(a(4)+T1.*(a(5)+T1.*a(6)))));
%cp_2 calculation, this is a function of T2
cp_2=a(1)+T2.*(a(2)+T2.*(a(3)+T2.*(a(4)+T2.*(a(5)+T2.*a(6)))));
%Compute Gamma as per equation given
gamma1=((cp_1)./(cp_1-R));
%This is a function of T2
gamma2=((cp_2)./(cp_2-R));
end
  댓글 수: 2
Andrew Newell
Andrew Newell 2011년 9월 28일
Please see http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question to format your code correctly.
Rick Rosson
Rick Rosson 2011년 9월 28일
Please format your code. If you do not know how, please click on the link called "Markup help" below.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 9월 28일
At the very least you need to move the f= line to the bottom of the function, as it relies upon values calculated or assigned in the function.
  댓글 수: 3
Korosh Agha Mohammad Ghasemi
Korosh Agha Mohammad Ghasemi 2020년 8월 3일
No, it is true that if passed down, the final wrong value will be obtained
Walter Roberson
Walter Roberson 2020년 8월 5일
Korosh Agha Mohammad Ghasemi could you expand on what you are saying? Can you give an example input T2 value that the code gives the wrong output for (after moving the assignment to f to the end), together with an indication of what the correct value should be for that input ?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Thermodynamics and Heat Transfer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by