- #1
beho86
- 25
- 0
Matlab Help! Euler method
Use Euler's method:
cooling constant r = 0.2 , initial temperature of 86 C, and room temperature at 17 C. Choose your time step h and integrate to 5 minutes.
You can add some cream which will drop the temperature instantly by 5 C.
(a) Now, add the cream at the beginning. Plot your results. What is the temperature after 5 min?
(b) Add the cream at the end. Plot the results (preferably on the same figure). What is the temperature at the end?
I started the program in matlab:
Code:
the problem is the plot only plots the last value in the loop, I tried to store it in an array, but I kept getting an error?
Use Euler's method:
cooling constant r = 0.2 , initial temperature of 86 C, and room temperature at 17 C. Choose your time step h and integrate to 5 minutes.
You can add some cream which will drop the temperature instantly by 5 C.
(a) Now, add the cream at the beginning. Plot your results. What is the temperature after 5 min?
(b) Add the cream at the end. Plot the results (preferably on the same figure). What is the temperature at the end?
I started the program in matlab:
Code:
Code:
clc
clear all
r=0.2;
T=86 ;
t=0 ;
Ts=17;
h=0.1 ;
nsteps=300 ;
for i=0:nsteps
fprintf('%0.2f %0.3f\n',t,T)
dT=-r*h*(T-Ts) ;
T=T+dT ;
t=t+h;
end
plot(t,T)
xlabel('Time (Sec)');
ylabel('Temperature (C)');
grid;
the problem is the plot only plots the last value in the loop, I tried to store it in an array, but I kept getting an error?