필터 지우기
필터 지우기

Turning a function into anonymous function

조회 수: 2 (최근 30일)
Maja Zdulska
Maja Zdulska 2021년 3월 17일
댓글: Maja Zdulska 2021년 3월 17일
Hi everyone,
I have this piece of code:
T_0 = 100; % initial temperature (deg C)
T_a = 10; % temperature of water used for cooling (deg C)
k = 0.034; % constant (dimensionless)
dt = 1; % temporal step (min)
Ts = 120; % prediction timespan (min)
t = [0:dt:Ts]; %temporal grid vector
%analytical solution
T_an1 = T_a+(T_0-T_a)*exp(-k*t);
T_an2 = @(t)T_a+(T_0-T_a)*exp(-k*t);
I would like to turn the function into anonymous (T_an2). Something is missing in the last line of the code, but I can't figure out what it is.
Any advice?

답변 (1개)

Alan Stevens
Alan Stevens 2021년 3월 17일
What do you think is wrong with it? It works ok. Add
plot(t,T_an2(t)),grid
at the end to see the result.
  댓글 수: 1
Maja Zdulska
Maja Zdulska 2021년 3월 17일
Oh, I think I was misleaded by the way it came out in the workspace.
Thanks anyway!

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by