% Delivered to the Government in Accordance with Contract FA8650-10-C-7080
% 
%  (c) 2011 United Technologies Corp.
% Developed with the sponsorship of the Defense Advanced Research Projects Agency (DARPA).
%  
% Permission is hereby granted, free of charge, to any person obtaining a copy of this data, including any software or models in source or binary form, as well as any drawings, specifications, and documentation (collectively "the Data"), to deal in the Data without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so, subject to the following conditions:
%  
% The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Data.
%  
% THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
% 


clear all; close all;

%CONSTANTS (all in SI)
T_inf = 300;  %Ambient Temperature K
T_Sky = 200;  %Sky Radiation Temperature K
d = 30/1000;  %Max Board Diameter m
t = 5/1000;   %Board Thickness m
L=d;          %PVC half-length 
Rcont_R = 5e-2; %Thermal Resistance  R and Wall
Rcont_C = 5e-3; %Thermal Resistance  C and Wall
k = .375;         %Thermal conductivity of board
h = 10;         %convection coefficient
R = 2;          %Resistance
options = optimset('display','off');
T0 = [600 500 400];  %guess temperatures

%EXAMPLE CALL
curr = 1.8;
Rboard = d/k;  %d is distance between R and C
Tans = fsolve(@RLC_Thermal_Equations,T0,options,curr,R,Rboard,Rcont_R,Rcont_C,d,t,L,h,T_Sky,T_inf);
%extra call to get Heat Structure (not needed)
[y, Heat] = RLC_Thermal_Equations(Tans,curr,R,Rboard,Rcont_R,Rcont_C,d,t,L,h,T_Sky,T_inf);

%MAKES Temperature vs Current plot
i_a = [0:0.1:1.8];
for i=1:length(i_a)
    curr = i_a(i);
    Tans = fsolve(@RLC_Thermal_Equations,T0,options,curr,R,Rboard,Rcont_R,Rcont_C,d,t,L,h,T_Sky,T_inf);
    TR_a(i) = Tans(1);
    TC_a(i) = Tans(2);
end
figure;plot(i_a,TC_a,i_a,TR_a);xlabel('current');ylabel('T (K)');
legend('T Cap','T Resis');grid on;text(0.5,550,['Thermal Resis = ', num2str(Rboard), ' m*m*K/W']);

%Makes temperature vs board thermal resistance plot
Rboard_a = [.004:0.002:0.1];
for i=1:length(Rboard_a)
    curr = 1.8;
    Rboard = Rboard_a(i); 
    Tans = fsolve(@RLC_Thermal_Equations,T0,options,curr,R,Rboard,Rcont_R,Rcont_C,d,t,L,h,T_Sky,T_inf);
    TR_ab(i) = Tans(1);
    TC_ab(i) = Tans(2);
end
figure;plot(Rboard_a,TC_ab,Rboard_a,TR_ab);xlabel('Thermal Resist (m*m*degK/W)');ylabel('T (K)');
legend('T Cap','T Resis');grid on; text(0.06,475,['Current = ', num2str(curr), ' A']);

%makes temperature vs length between R and C plot
length_a = [0.001:0.001:0.03];
for i=1:length(length_a)
    curr = 1.8;
    Rboard = length_a(i)/k; 
    Tans = fsolve(@RLC_Thermal_Equations,T0,options,curr,R,Rboard,Rcont_R,Rcont_C,d,t,L,h,T_Sky,T_inf);
    TR_aL(i) = Tans(1);
    TC_aL(i) = Tans(2);
end
figure;plot(length_a,TC_aL);xlabel('Distance R to C (m)');ylabel('T Capacitor (K)');
grid on; text(0.06,475,['Current = ', num2str(curr), ' A']);
