How to plot same function from different starting positions
Afficher commentaires plus anciens
So I want to plot a function of temperature over time, however I want to see how the temperature changes when it's at different starting points going from 0 to 28 going in steps of 2.
Is there a simple way to change the starting point and have it all plot on the same graph without having to rewrite the function out multiple times?
This is the code:
C = 51
absorbed_solar_radiation = 239.4 ;
A = 221.2 ;
B = -1.3 ;
greenhouse_effect_PI = 0
dt = 1 ;
T0 = 5 ; %This is the starting temperature I want to change
T(1) = T0 ;
t0 = 0 ;
t(1) = t0 ;
n_step = 200 ;
for n = 1:n_step ;
t(n+1) = t(n) + dt;
T(n+1) = T(n) + (dt/C)*(absorbed_solar_radiation - (A - B*T(n)) + greenhouse_effect_PI) ;
end
plot(t,T, 'b.-')
xlabel('years')
ylabel('temperature')
The temperature should always tend to 14. So my question is, is there a neat way to change 'T0' without having to list all the starting points as different variables and have to write out:
T(n) + (dt/C)*(absorbed_solar_radiation - (A - B*T(n)) + greenhouse_effect_PI) ;
multiple times?
Réponse acceptée
Plus de réponses (1)
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
