Inputs must be floats, namely single or double.

4 Ansichten (letzte 30 Tage)
Ada-Natalia Luukkanen
Ada-Natalia Luukkanen am 9 Apr. 2021
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?

Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 9 Apr. 2021
Bearbeitet: Bjorn Gustavsson am 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 Kommentare
Ada-Natalia Luukkanen
Ada-Natalia Luukkanen am 9 Apr. 2021
I got it working! Thank you again for your help :)
Bjorn Gustavsson
Bjorn Gustavsson am 9 Apr. 2021
You're welcome.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by