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 Center および File ExchangeThermodynamics and Heat Transfer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by