Inputs must be floats, namely single or double.
조회 수: 5 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!