Comparing orbits between a planet and Red Dwarf I have a MATLAB problem, so I have an earth like planet orbiting around a sun like star and then there is a red dwarf on an elliptical orbit around the star that passes close to the planet. I want to show that sometimes when the Red Dwarf is at it's closest approach the planet may not be there so it won't gain any heat from the red dwarf. 

To do this I was told to compare the orbital periods of the two. So for the planet it's orbital period is just like the earth 365 days and the red dwarf's period is 1896.59 days. 

I was thinking is there a way I could plot the orbits of these two and run it for say like 100 years and see the if there is points when the earth could miss the red dwarf? If this is wrong please let me know a better way of tackling this problem. 
Below is an image of the orbit, with the black line being the red dwarf's orbit and the  blue line being the planet's orbit. The eccentricity of the Red Dwarf's orbit is 0.866 since a=3 Au and b=1.5 Au.
earth like planet orbiting around a sun like star (365 days)
red dwarf on an elliptical orbit around the star that passes close to the planet (1896.59 days, eccentricity 0.866)

If we work in AU and years we can use $GM_{Sun} = 4 \pi^2 (\text{AU}^3 / \text{year}^2)$ for the standard gravitational parameter of the Sun. If we also assume the red dwarf's mass is small enough that it can be ignored we can leave the Earth in it's circular 1 AU orbit and assume that the Sun doesn't move. Then we can check the relationship between period and semimajor axis as follows:
$$T = 2 \pi \sqrt{\frac{a^3}{GM}} = a^{3/2}$$
$$a = T^{2/3} \left(\frac{GM}{4 \pi^2}\right)^{1/3} = T^{2/3}$$
which gives $a=1$ AU for 1 year, and $(1896.59/365)^{2/3} \approx 3 $ AU for the red dwarf so this checks out.
However your drawing is off. The periapsis and apoapsis of the red dwarf will be $3(1-e)$ and $3(1+e)$ or 0.4 and 5.6 AU and this plus this comment makes it clear that your drawing is wrong.
If the ratio of the two periods were a rational number, say $T_2/T_1 = n_2/n_1$ where $n_1, n_2$ are integers, then their relative motion would be periodic with the synodic period
$$T_S = \frac{1}{\frac{1}{T_1} - \frac{1}{T_2}} = \frac{T_1 T_2}{T_2 - T_1} = \frac{n_1 n_2}{n_2 - n_1}$$
but the distance of closest approach would depend on phasing; the initial positions at time $t=0$.
However in your case you have $a_2/a_1 = 3$ and so $T_2/T_1 = 3 \sqrt{3}$ which is irrational and not expressed as the ratio of two integers. That means that if these two orbits are in the same plane and the two bodies do not interact gravitationally with each other, sooner or later they may collide.

Python:
import numpy as np
import matplotlib.pyplot as plt

twopi = 2 * np.pi
a1, e1 = 1.0, 0.0
a2, e2 = 3.0, 0.866

theta = np.linspace(0, twopi, 201)

r1 = a1 * (1. - e1**2) / (1. + e1 * np.cos(theta))
r2 = a2 * (1. - e2**2) / (1. + e2 * np.cos(theta))

x1, y1 = [-r1 * f(theta) for f in (np.cos, np.sin)] # minus to match plot in question
x2, y2 = [-r2 * f(theta) for f in (np.cos, np.sin)]

plt.figure()
plt.plot(x1, y1, '-b', linewidth=2)
plt.plot(x2, y2, '-k', linewidth=1)
plt.plot([0], [0], 'or')
plt.gca().set_aspect('equal')
plt.xlim(-3.2, 6.8)
plt.ylim(-4, 4)
plt.xlabel('Distance (AU)', fontsize=14)
plt.ylabel('Distance (AU)', fontsize=14)
plt.show()