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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by