Solving a linear ODE with along with an unknown constant.

Hi! I'm new to Matlab and I currently have the following problem:
Ta = 20;
syms T(t);
ODE = diff(T,t) == -k*(T-Ta);
cond_1 = T(0) == 29.5;
cond_2 = T(2) == 23.5;
ODE_sol(t) = dsolve(ODE, cond_1, cond_2);
I'd like to define 'k' as a constant that's unknown until I solve for the ODE with the 2 boundary conditions, and 'syms k' doesn't seem to work. Thanks in advance.

 Respuesta aceptada

syms k certainly does work.
Ta = 20;
syms k
syms T(t)
ODE = diff(T,t) == -k*(T-Ta);
dsolve(ODE)
ans =
C1*exp(-k*t) + 20
So k is a symbolic constant. syms did work. I'm not sure what you are saying.
This is a first order ODE. As you see, solved without any boundary conditions, we find one unknown constant. We can use only one boundary condition to eliminate the unknown constant.
Are you asking how to solve the problem with TWO boundary conditions, so thus solving also for k?
cond_1 = T(0) == 29.5;
odesol = dsolve(ODE,cond_1)
odesol =
(19*exp(-k*t))/2 + 20
Now, we can solve for k, using the second boundary condition.
ksol = solve(subs(odesol,t,2) == 23.5)
ksol =
-log(7/19)/2
subs(odesol,k,ksol)
ans =
(19*exp((t*log(7/19))/2))/2 + 20
I imagine there are other ways I could have done this.

1 comentario

Juan Castañeda
Juan Castañeda el 19 de Dic. de 2020
Editada: Juan Castañeda el 19 de Dic. de 2020
Thanks a lot, that's exactly what I was asking for. I was so frustrated that I couldn't see how easy it actually was.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 19 de Dic. de 2020

Editada:

el 19 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by