what code should i use to plot the set of resulting values?

1 view (last 30 days)
THIS IS THE CODE:
disp('Newtons law of cooling problem #3 using dT/dt=k*(Ta-T) and Eulers Method')
k=input('ENTER k: ');
Ta=input('ENTER Ambient Temperature Ta: ');
T0=input('ENTER Temperature at time of Death: ');
t0=input('ENTER Initial Time: ');
h=input('ENTER delta t: ');
ts=input('ENTER Time step: ');
n=(ts-t0)/h;
t(1)=t0;y(1)=T0;
T= @(t,y)((-k)*(y-Ta));
disp(' The Temperature per delta t is: ');
for i=1:n
y(i+1)= y(i)+h*T(t(i),y(i));
t(i+1)= t0+i*h;
fprintf(' y(%.2f)=%.4f\n',t(i+1),y(i+1))
end
THESE ARE THE OUTPUT:
Newtons law of cooling problem #3 using dT/dt=k*(Ta-T) and Eulers Method
ENTER k: 0.12
ENTER Ambient Temperature Ta: 10
ENTER Temperature at time of Death: 37
ENTER Initial Time: 0
ENTER delta t: 0.5
ENTER Time step: 5
The Temperature per delta t is:
y(0.50)=35.3800
y(1.00)=33.8572
y(1.50)=32.4258
y(2.00)=31.0802
y(2.50)=29.8154
y(3.00)=28.6265
y(3.50)=27.5089
y(4.00)=26.4584
y(4.50)=25.4709
y(5.00)=24.5426

Answers (1)

Cris LaPierre
Cris LaPierre on 31 Jul 2021
See Ch 9 of MATLAB Onramp.

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!