How to invoke my function in my code ?

4 ビュー (過去 30 日間)
Hannah Mohebi
Hannah Mohebi 2022 年 3 月 4 日
コメント済み: Torsten 2022 年 3 月 4 日
I want to invoke H in my code which is needed to calculate T in for loop. H is enthalpy which is a function of Cp and I attached the function.But I faced an error.Would you please help me to corret it and invoke H in my code truely?
H function:
function [H]=enthalpymethod(T)
syms x
deltaT=2;
T_c=27;
LH=179000; %J/kg
Cps=2000; %J/kg.K
Cpl=2000; %J/kg.K
Cp=(LH/(2*deltaT))+(Cpl+Cps/2);
if T<(T_c-deltaT)
H=vpaintegral(Cps,x,[0 T]);
elseif (T<=(T_c+deltaT)) && (T>=(T_c-deltaT))
H=vpaintegral(Cps,x,[0 T_c-deltaT])+int(Cp,x,[T_c-deltaT T]);
elseif T>(T_c+deltaT)
H=vpaintegral(Cps,x,[0 T_c-deltaT])+int(Cp,x,[T_c-deltaT T_c+deltaT])+int(Cpl,x,[T_c+deltaT T]);
end
end
My code:
clc;
T=zeros(2,1);
T(1,1)=30;
for i=1:2
for j=1
enthalpymethod(T(i+1,j))=enthalpymethod(T(i,j))+20;
end
end
disp(enthalpymethod(T(3,1)))
  2 件のコメント
Stephen23
Stephen23 2022 年 3 月 4 日
enthalpymethod(T(i+1,j))=enthalpymethod(T(i,j))+20;
It is unclear what you expect to achieve, but your code syntax is not valid:
You cannot name a variable with the same name as your function.
You cannot allocate data to a function, as you seem to be attempting.
Hannah Mohebi
Hannah Mohebi 2022 年 3 月 4 日
I simplified my equation. Indeed I want to solve the attached equation, which needs to invoke H in for loop for calculating T.How can I code this?

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

回答 (1 件)

Hannah Mohebi
Hannah Mohebi 2022 年 3 月 4 日
I simplified my equation. Indeed I want to solve the attached equation, which needs to invoke H in for loop for calculating T.How can I code this?
  3 件のコメント
Hannah Mohebi
Hannah Mohebi 2022 年 3 月 4 日
This equation is for modelling PCM with enthalpy method.This equation is in a paper which I want to validate.
Torsten
Torsten 2022 年 3 月 4 日
What is the algebraic equation relating H and T ? Do cps, cp and cpl depend on T ? If not (as in your code from above), you don't need any integration - you can directly solve for H resp.T.

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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by