How to invoke my function in my code ?

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 Comments

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.
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?

Sign in to comment.

Answers (1)

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 Comments

The heat equation reads
rho*cp*dT/dt = d/dx ( lambda*dT/dx)
Why do you work with enthalpies here ?
This equation is for modelling PCM with enthalpy method.This equation is in a paper which I want to validate.
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.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 4 Mar 2022

Commented:

on 4 Mar 2022

Community Treasure Hunt

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

Start Hunting!