How to plot this function?

조회 수: 5 (최근 30일)
Alejandra
Alejandra 2014년 12월 12일
답변: Ingrid 2014년 12월 12일
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

답변 (1개)

Ingrid
Ingrid 2014년 12월 12일
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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by