How to invoke my function in my code ?

4 vues (au cours des 30 derniers jours)
Hannah Mohebi
Hannah Mohebi le 4 Mar 2022
Commenté : Torsten le 4 Mar 2022
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 commentaires
Stephen23
Stephen23 le 4 Mar 2022
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 le 4 Mar 2022
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?

Connectez-vous pour commenter.

Réponses (1)

Hannah Mohebi
Hannah Mohebi le 4 Mar 2022
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 commentaires
Hannah Mohebi
Hannah Mohebi le 4 Mar 2022
This equation is for modelling PCM with enthalpy method.This equation is in a paper which I want to validate.
Torsten
Torsten le 4 Mar 2022
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by