A metal bar is heated 100oc by a heat source. After 40 minutes the heat source is removed when the temperature of the metal bar reached to a plateau. Now the metal bar is placed in a room. The room temperature is 25oc. After 10 minutes the bar temperature reached to 80oc. a) What is the initial temperature of the metal bar. b) Find the metal bar temperature after 30 minutes.
How to solve this using Numerical Solution? I am trying to solve this using Euler method, but I only could finish upto this:
dT/dt (t)=(T(t+Δt)-T(t))/Δt
T(t+Δt)=T(t)-Δtk(T(t)-Ta )
Then I stucked. please help.
The equation you are trying to simulate is
$$\frac{{\rm d}T}{{\rm d}t} = -k \Bigl( T - T_a \Bigr) $$
This is a classic ordinary differential equation (ODE) of the form $T'= f (T)$ where $T'$ is the derivative and $T$ the quantity to be solved for.
Starting from any time step with a temperature $T_i$ at time $t_i$, you progress to the next time step $t_{i+1}=t_i+h$ using Euler's method which states $T_{i+1} = T_{i} + h f(T_i)$. So for each time step you do the following
$$ T_{i+1} = T_i + h \left(- k \Bigl(T_i - T_a \Bigr) \right) = T_i - k\, h \left( T_i -T_a \right)$$
And that is all you need to before it becomes a programming question and not a math question. You already have this equation since $h=\Delta t$.
In pseudo-code the above would look like this: