Inputs must be floats, namely single or double.
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Bjorn Gustavsson
on 9 Apr 2021
Edited: Bjorn Gustavsson
on 9 Apr 2021
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 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!