Inputs must be floats, namely single or double.

조회 수: 5 (최근 30일)
Ada-Natalia Luukkanen
Ada-Natalia Luukkanen 2021년 4월 9일
댓글: Bjorn Gustavsson 2021년 4월 9일
I am trying to solve an ODE about newton's cooling law and plot it:
this is my script called newton.m
function dTdt = newton (t,T)
t = (0:1:80)';
syms T(t);
dTdt = 0.1*(20-T);
end
and here is another script called newton_plot
function newton_plot
newton
[x, y] = ode45(@(x,y)newton,[0 80],100);
plot(x,y,'-o')
end
I tried bringing the newton function to the newton_plot function in the beginning of the newton_plot function. (not sure if it works)
I get errors like:
>> newton_plot
ans(t) =
2 - T(t)/10
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in newton_plot (line 6)
[x, y] = ode45(@(x,y)newton,[0 80],100);
How can I get it to work?

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 9일
편집: Bjorn Gustavsson 2021년 4월 9일
When you integrate an ODE numerically there is no need whatsoever to introduce a declaration of T as a symbolic variable (the way you do it the input-argument T is even destroyed...). It should be enough to do this:
function dTdt = newton (t,T)
dTdt = 0.1*(20-T);
end
That should be enough to define your cooling-ODE. That is if your cooling characteristics are something like this:
HTH
  댓글 수: 4
Ada-Natalia Luukkanen
Ada-Natalia Luukkanen 2021년 4월 9일
I got it working! Thank you again for your help :)
Bjorn Gustavsson
Bjorn Gustavsson 2021년 4월 9일
You're welcome.

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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by