Function handle doesn't work as intended

조회 수: 7 (최근 30일)
Karsten Gros
Karsten Gros 2017년 6월 15일
댓글: Karsten Gros 2017년 6월 28일
Hi, I have a question regarding my matlab-code. Basically, the code should calculate the heat-transfer for drop-wise condensation. At the end of the program, I should have a funvtion with deltaT as variable parameter. But the error-message basically says that .* can't be used with function handles. I attached the file, so if anyone is willing to help me, you would make me very happy :) Any ideas how I could get the program fixed? Thanks in advance and best regards, Karsten
  댓글 수: 2
James Tursa
James Tursa 2017년 6월 15일
Please copy and paste the entire error message so we know which exact line is causing the problem and which exact error message MATLAB is giving you.
Karsten Gros
Karsten Gros 2017년 6월 15일
편집: James Tursa 2017년 6월 15일
Hi, thanks for your quick response. Here's the error message:
Undefined operator '.*' for input arguments of type 'function_handle'.
Error in
qi_neu>@(deltaT)2./r_c.*((1+cos(Theta)./(2.*h_i)+delta./(lamda_coat.*sin(Theta).^2)+(r.*Theta)./(4.*lamda_l.*sin(Theta)))).^(-1).*r_c.^2.*pi.*(deltaT.*ln(r_c./r_min(deltaT))+2.*T_sat.*sigma./(H_fg.*rho_l).*(1./r_c-1./r_min(deltaT)))
Error in qi_neu (line 97)
q_tot1(1)

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2017년 6월 15일
Q = @(r, deltaT) pi.*r.^2.*(deltaT-(2.*T_sat.*sigma)./(H_fg.*r.*rho_l)).*((1+cos(Theta)./(2.*h_i)+delta./(lamda_coat.*sin(Theta).^2)+(r.*Theta)./(4.*lamda_l.*sin(Theta)))).^(-1)
needs to be
Q = @(r, deltaT) pi.*r.^2.*(deltaT-(2.*T_sat.*sigma)./(H_fg.*r.*rho_l)).*((1+cos(Theta)./(2.*h_i(deltaT))+delta./(lamda_coat.*sin(Theta).^2)+(r.*Theta)./(4.*lamda_l.*sin(Theta)))).^(-1)
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 6월 17일
When that change is made, that error message disappears, leaving you with other error messages.
  • You use delta_T twice in one of the lines, instead of deltaT
  • You use r once in a line where r has not been defined; it appears that should be r_c which is used multiple times on that line
  • You call upon ln() instead of log() . That is not an uncommon error -- and yet when I research I have been unable to find any major programming language that calls it ln()
Revised code attached. I have no idea if the correct value is calculated.
James Tursa
James Tursa 2017년 6월 19일
Not a "major programming language", but MS Excel uses ln() for natural log.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

James Tursa
James Tursa 2017년 6월 15일
Just quickly looking though what was posted, this line:
grid onq_tot2 = @(deltaT) integral(@(r) stopp(r), r_c, r_max)
looks like it should be two separate lines:
grid on
q_tot2 = @(deltaT) integral(@(r) stopp(r), r_c, r_max)

Karsten Gros
Karsten Gros 2017년 6월 19일
편집: Karsten Gros 2017년 6월 19일
Hi, your corrections worked ;) Thank you very much. Could you give me a hint where you replaced the r with the r_c? And When I tried to plot the end-equation, It didn't work. Any hints for that one? (It works for q_tot1, but not for q_tot2 or q_tot) Best regards :)
  댓글 수: 8
Walter Roberson
Walter Roberson 2017년 6월 28일
No, you have not defined dT for that last line. Is there a reason you changed it from
q_tot = @(deltaT) q_tot1(deltaT)+q_tot2(deltaT);
Variable names do NOT need to match in the calling function and the called function! Variable names need to be consistent within any one function.
Karsten Gros
Karsten Gros 2017년 6월 28일
It actually works, thank you very much :) I learnt a lot ;)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by