iterations / trial and error method to find a variable.

I have this enthalpy equation where all the variables are known but the temperature T2. I want to write a code to find the best possible solution for T2 by iteration / trial and error method. you can start from T2= 400 for instance.
deltah=a(T2-T1)+(b/3)*(T2^2-T1^2)+(c/3)*(T2^3-T1^3)+(d/4)*(T2^4-T1^4)
a=28.9; b=0.1967*10^-2; c=0.4802*10^-5; d=-1.966*10^-9; dltH=8900; T2=400; T1=300;

 採用された回答

Jan
Jan 2018 年 5 月 12 日
編集済み: Jan 2018 年 5 月 12 日

1 投票

You can use fzero to solve this 3rd order polynomial.

3 件のコメント

dpb
dpb 2018 年 5 月 12 日
which would look like
>> fndH=@(T2) a*(T2-T1)+(b/3)*(T2^2-T1^2)+(c/3)*(T2^3-T1^3)+(d/4)*(T2^4-T1^4)-dltH
fndH =
function_handle with value:
@(T2)a*(T2-T1)+(b/3)*(T2^2-T1^2)+(c/3)*(T2^3-T1^3)+(d/4)*(T2^4-T1^4)-dltH
>> fzero(fndH,T2)
ans =
593.8714
>> fndH(ans)
ans =
0
>>
Tarek Chaabo
Tarek Chaabo 2018 年 5 月 13 日
thank you so much i learned something new. Is there another way where i can see each value of T2 printed to the command window until the final value of 593.8714 ??
dpb
dpb 2018 年 5 月 13 日
Read the documentation; specifically look at the additional, optional input argument list...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDebugging and Analysis についてさらに検索

質問済み:

2018 年 5 月 12 日

コメント済み:

dpb
2018 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by