P3: Given Scripts/Functions

P3A
% Script P3A
close all

P = 10;  % Distance from sun at perihelion
A = 20;  % Distance from sun at aphelion
T = 60;  % Length of Year in days.

% Generate the orbit spline based on nSect sectors
% and show orbit points for each day in the year.

nSect = 200;
S = OrbitSpline(P,A,T,nSect);
[x,y] = OrbitVals(S,P,A,linspace(0,T,T+1));
plot(x,y,'.')
axis equal off

% Divide the year into m equal parts and show
% the radius vector at t = linspace(0,T,m+1)

m = 13;
hold on
plot(0,0,'*')
[x1,y1] = OrbitVals(S,P,A,linspace(0,T,m+1));
for k=1:m
   plot([0 x1(k)],[0 y1(k)])
end

% Simulate the orbiting body for the first e years.

tFinal = exp(1)*T;
cometVals = 10000;                    % Bigger values slow the simulation
tvals = linspace(0,tFinal,cometVals);
[x0 y0] = OrbitVals(S,P,A,tvals);
comet(x0,y0,.02)
text(-28,14,sprintf('A = %5.2f',A))
text(-28,12,sprintf('P = %5.2f',P))
text(-28,10,sprintf('T = %5.2f',T))
text(-28, 8,sprintf('tFinal = %5.2f',tFinal))
text(-28,-12,sprintf('x = %15.12f',x0(cometVals)))
text(-28,-14,sprintf('y = %15.12f',y0(cometVals)))
hold off
P3C
% P3C
% Tests the function Poisson

clc
disp('A small example to check correctness:')
disp(' ')
m = 4; t = Poisson(m);
for i=1:m
   disp(sprintf('%10.6f   ',t((i-1)*m+1:i*m)))
end

% A larger example with the solution displayed as a contour plot.
m = 20; t = Poisson(m);

% Set up (m+2)-by-(m+2) matrix of temperature values
T_inside = zeros(m,m); T_inside(:) = t; T_inside = T_inside';
T = zeros(m+2,m+2); T(2:m+1,2:m+1) = T_inside;
h = 1/(m+1); v = linspace(h,1-h,m); north_vals = 100*sin(pi*v).*exp(-2*v);
T(1,2:m+1) = north_vals;

% Produce the contour plot
x = linspace(0,1,m+2);
c = contour(x,x,T(m+2:-1:1,:),[30 20 10 5 3 2 1]);
clabel(c)
axis square