Inputs must be floats, namely single or double.

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?

Answers (1)

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

Thanks for your answer. I took off the dedundant lines. Now I get errors like this
>> newton_plot
Not enough input arguments.
Error in newton (line 4)
dTdt = 0.1*(20-T);
Error in newton_plot (line 2)
newton
once again, this is now my newton.m script:
function dTdt = newton (t,T)
dTdt = 0.1*(20-T);
end
and this is my newton_plot.m script:
function newton_plot
newton
[x, y] = ode45(@(x,y)newton,[0 80],100);
plot(x,y,'-o')
end
I got it working! Thank you again for your help :)

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!