Plotting period using values from a for loop
Show older comments
I have this code I am working on that is plotting the temperature of a planet that is orbit a star but there is a red dwarf star on an elliptical orbit around the main star and I wanted to calculate the temperature of the planet based its distance from the two stars. That part I have done, next part I want to do is plot the change of temperature against the orbital period of the red dwarf.
Some info on the Red Dwarf, its orbital period is 1896.59 days and its distance from the planet varies from 3.75 AU to 0.25 AU. The idea for the plot is to say that at day 1 the red dwarf starts its orbit at 3.75 AU, then takes half of its orbit (948.3 days) to get to the distance of 0.25 AU then the rest of its orbital period to return back to 3.75 AU. The problem I was running into when trying to plot this was that it kept plotting the whole range of values for the planets temperature every day. What I want is to say at day 1 when it is at 3.75 AU the planets temperature is this, and then do the same for every day during the red dwarf's orbit.
Any help would be great, I have attached my code below and an output image of what I am getting currently.
%Written by Adam Kelly
clear all;
clc;
%constants
r=1.5e+10;
rs=6.261e+8; %Radius of Star
ro=1.49e11; %Sun orbital radius (1 AU)
rRD=1.25e8 ; %Radius of Red Dwarf
stefconst=5.67e-8; %stefan-boltzmann constant
T=5200.2; %Temp of Sun
TRD=3773.15; %Temp of Red Dwarf
al=0.3; %albedo
a=3; %Red Dwarf's semi major axis
G=6.67408e-11;
MS=2e+30;
MP=5.972e+24;
MRD=1.2e+30;
%luminosity of star
Ls=4*pi*rs^2*stefconst*T^4;
Lrd=4*pi*rRD^2*stefconst*TRD^4;
fluxS=(Ls./(4*pi*ro^2));
%Red Dwarf's Period
%Using Kepler's 3rd law
P=a.^1.5; %Gives answer in years
PRD=P*(365)
vTP=[];
for roRD=3.75:-0.01:0.25
%Flux
fluxRD=(Lrd./(4*pi*(roRD*1.496e11)^2)); %flux of red dwarf
fluxAverage=(fluxS+fluxRD);
%Temp of planet
Tplanet=((fluxAverage*(1-al))./(4*stefconst))^0.25;
TP=Tplanet-273.15
vTP(end+1) = TP;
subplot(2,1,1);
plot(roRD,TP,'.r')
hold on
xlim([0 4])
ylim([-58 -44])
xlabel('Orbit(AU)')
ylabel('Temperature of Planet(C)')
end
for P=1:+5:1896
subplot(2,1,2);
plot(P,vTP,'.b');
hold on
xlim([0 1896])
ylim ([-58 -45])
end

Accepted Answer
More Answers (0)
Categories
Find more on Earth and Planetary Science in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!