How to plot this function?

5 vues (au cours des 30 derniers jours)
Alejandra
Alejandra le 12 Déc 2014
Réponse apportée : Ingrid le 12 Déc 2014
I have this function that allows me to work out what the temperature is according to CO2. However, I wanted to know how could I plot temperature as a function of CO2 concentrations.
This is the function that tells me how to get from a certain CO2 value to a Temperature value for that CO2 however I'd like to plot it as a graph.
if true
function temperature(carbon)
s0=1367.6; %constant parameter
a=0.3; %albedo
A=-129.2684; %constant
B=142.6046; %another constant
eps=A/(B-carbon);%green house value as a function of CO2 concentration
sigma=5.67*(10^(-8)); % constant parameter
t=((s0*(1-a))/(eps*(4*sigma)));
temperature = t^(1/4)
end
% code
end

Réponses (1)

Ingrid
Ingrid le 12 Déc 2014
just create a vector of relevant CO2 concentrations and call your temperature funciton for each value
so:
carbon = 1:10:1000; % place here your relevant concentrations that you want to plot
temperatureY = zeros(length(carbon),1);
for ii = 1:length(carbon)
temperatureY(ii) = temperature(carbon(ii));
end
plot(carbon,temperatureY);
you need the for loop here because your function cannot deal with vectors so if speed of your code is an issue this is something you can still improve

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by