CS193p Github
I created a github account to store my cs193p assignment results.
My first repository Calculator is to the store all the work on the calculator. This covers assignment 1 to 3.
I intend to commit all small changes to the application closely following the parts of the assignment and documenting the hints from the assignment and the courses. Unfortunately I have to redo my assignements again to create the required commits.
CS193p Delegation concepts
Delegation is a rather difficult concept to understand. In order to get a better idea what it is I made a drawing.
Suppose we have three object: a square, a circle and a pentagram. The square has four white holes in itself (an oval, a 4-pointer star (not quite white), a 5-pointed star and a hexagram). It announces to the world that another object can fill these holes (the lines protruding the square). In fact it needs two other objects: one for the blue holes and one for the red holes.
The circle object announces that it will help the square object with its blue holes. And the pentagram object says it will help with the red holes. Thus the circle object fills the blue oval hole of the square object. And the pentagram object fills the red pentagram hole and the 5-pointed star hole of the square object. The four pointed star has not been filled as it was optional (not quite white).
With this it is possible to explain the various delegation concepts:
- delegator - the square object is the object that delegates;
- delegatee - the round and the pentagram objects adopt the delegation responsibilities;
- delegate property - the square wants to know who his delegatees are. This is specified in his delegator properties (the two extrusions on the square). One of the extrusions is filled by the circle, the other by the pentagram;
- protocol- the set of holes in a specific colour define a protocol. The small square on the edge of the circles says that the circle adopts the blue protocol as defined by the square. The same goes for the red protocol on the pentagram;
These leads to the five steps defined in course 7(?). Two steps are definition and three steps are adoption:
- Protocol - define the methods for a protocol;
- Delegator - define who needs to delegator a protocol;
- Adoption - a class (delegatee) should declare it adopts a certain protocol;
- Implementation - the delegatee should implement the methods required in the protocol by the delegator;
- delegator properties - the delegator properties that point to its delegatees should be set;
CS193p Assignment 4
I started working on Assignment 4 of the CS193 fall 2011 course.
- Flickr API - I got the Flickr API working and am able to access the top locations and photos per locations. I did have a bit of trouble figuring out the data structure that Flickr is giving. I got mixed up in Array’s and Dictionaries. Why does the flickrFetch API give an NSArray and not an NSDictionary?
- Storyboard - I had a lot of trouble getting a good storyboard. However after seeing Lecture 10, I decided to delete everything and restart from scratch. Just as Paul Hegarty did during the Lecture. And then everything went pretty smooth;
- Place Photolist - Getting the Photlist for a specifc place working got me bogged down for a while. Until I realised that I did not check the Segue identifier in the right way. I used ‘==’ and not ‘isEqual:’. After that it worked well;
- Spinner - I copied the Spinner idea from teh Lecture, but nothing happens. Do not know why;
- Description dictionary - I was not able to get the information on the description through the ‘description._content’-key. So I had to take the long way to retrieve it;
- Title and description length - the lenghts of these two items is much longer than the screen width. What is the best way to present them?
- Photo location list segue - I do not understand how this segue works. You do not have to set something up. Just add the segue to a table view controller seem to be enough to have it respond to a row selection? From where should I setup the segue? The window? the table? the cell? The window as anchor works with a performSegue: in didSelectRow:, but why?)
- Titles - I have been playing with the window titles a bit in order to display city name and or photo title. I would like to limit the number of characters and append a ‘...’ at the end. If I use a minimum size that is to large I get an error message. So I must take into account the maximum allowed length. Still have to work on that;
- Photo display - I got the photo displaying working, but I am not able to set it to fill with UIContentMode. Do not know what is wrong;
- iPad - I had to rewatch the course on the iPad to see how it worked again. Setting up the storyboard was reasonable straightforward. I had to remember to setup the photoViewController as detailedView. And to not use segue to present photo’s. It seems to be working. I have now to address the details;
CS193p Post Assignment 3 thoughts
I finished assignment 3 now, apart from the content scaling thing.
In course 9 the TableViewController was introduced. I added the instructions as given during the course. It all worked like a charm. I did however a few things a bit different: all buttons were added to the toolbar in the iPad storyboard.
Paul Hegarty was not able to all the relevant things in the course, so extra code was posted on the website. I folded all the posted code into my code. I used a slightly different approach to the iPhone storyboard: I added a toolbar at the bottom of the GraphView and put the formula, switch and add to favorites in there.
I am however left with one problem: the swipe gesture does not work. I still have to find a way to debug this. At the moment I am lost. It seems that the swipe-gesture is not recognized.
CS193p fall 2011 resources
This post gathers interesting resources I found for the fall 2011 course.
The official material can be found on the course website at Stanford and on iTunesU. These lectures are based on Xcode 4 and iOS 5, so the older solutions are no longer applicable. There can be some help found in a corresponding Google Group.
There are multiple people that I are following the course:
I found various solutions on the web, which work as inspiration.
Assignment 1 (Simple Calculator)
Assignment 2 (Programmable Calculator):
- Geekapproach - looks like an interesting solution to evaluate the expression;
- maxkostow - combined code for assignment 1-3;
Assignment 3 (Graphing Calculator):
- maxkostow - combined code for assignment 1-3;
- Jeffrey Lam - solution does not seem to use a datasource;
CS193p Assignment 2 thoughts
In this post I gather some thoughts on the assignment 2:
- protocols - for the iPad application to work one has to define a protocol in a separate-file. I just followed the directions in the lecture, but I am still at a loss how this works;
- error handling - in one of the earlier assignments one had to implement some error handling (division by zero). This should also propagate to the Graphing Calculator, which I did not implement;
- Points vs. pixels - the assignment asks to use this conversion in order to have the app working on retina displays. So I added this scale factor and thus doubled the number of calculations. However it does not seem to make any difference. So I am lost here;
- drawing mode - I had some problems implementing the drawing mode (line vs points). I added a segmented switch to the iPhone and iPad GraphController views. These call a method drawingModeChanged in the GraphController, which in turn changes the corresponding instance variable in Graph. But I was not sure in what method to set the drawing mode. After some experimenting I found the right one (tell you later which one);
- Xcode crash - I experienced a heavy Xcode crash. The application would no longer star with my project. I tried to use Time Machine to get a valid version back, but that did not work. So I recreated the project and pulled in the old files one by one. I was able to pull them all in without any problems. So I guess one of the project-files got corrupted;
- Profile - the final part of this assignment involved optimizing the code for the pinching gesture. I did not finish this, as it seemed to involved a lot of rewriting. I guess that one has to use a CGContextScaleCTM to change the scale;
IOS programming
And again I started learning IOS-programming. The last time I did finish the book by LaMarche for beginners. However I did not feel confident enough to work on my own. I started with the CS193p course that was then available, but got bogged down in mismatching courses and materials.
So a new year seem to be a good start to begin. I found out that in the mean time Xcode was heavily changed and IOS moved to version 5. This implied that I really had to start from the beginning. I am now up to course 7 and finished assignment 2.
Bundle time
It seems that it is the time of the year for all sorts of bundles.
The bundle of Productive Macs looks at productivity apps, such as Fantasical, BusyCal, Home Inventory, NotBook, Folder X, LaunchBar, Cashculator and Tags. They offer also some prize. Anyway the bundle is not for me, I have already enough related apps. I like the prizes though, such as Hype.
The MacUpdate bundle seems more interesting with TechTool Pro, IconBox, TotalFinder, Postbox 3, FontPack pro Master, Labels&Adresses;, Mac DVDRipper Pro 3, Back in Focus, NeverWinter Nights, Hear, iClip 5 and FolderSynchronizer. I like TechTool as I have not really something comparable. TotalFinder looks interesting. A DVDRipper useful (Handbrake?). Back in Focus and iClip (have an old version).
Effect of eccentricity

Simultaneous fitting two transits of an eclipsing binary is not evident. It is not allways clear how the various parameters interact. For SPH10003247 I used this approach:
- start fitting the secondary (shallowest) transit by changing the relative luminosity of the stars. A luminosity ratio of 0.55 matches the secondary transit. And also the primary transit can be matched (black lines in figure). A further increase (say 0.52) of the luminosity difference will make the secondary transit to shallow. A decrease (0.6) will make the primary transit not deep enough.
- A shallow secondary transit can also be produced by having a size difference between the two stars. Increasing the size of the secondary star to 1.26, will produce the right secondary depth. However this will not produce the right depth of the primary transit. The advantage of a size ratio is also that we will have a flat transit as we have in the data.
- Using a luminosity difference seems to be the preferred explanation. The next thing we need to explain is the shape of the bottom of the transits. Unfortunately any change to the size ratio will make the depths shallower, so a correction to the luminosity ratio must be applied as well. Thus we need to increase the size of the secondary star whilst decreasing the luminosity ratio. Unfortunately at a size ratio of 1.15 and brightness ratio of 0.72, the primary transit is no longer deep enough.
- It is also possible to move in the other direction: decreasing size ratio and increasing the luminosity ratio. It is not possible to go below a luminosity ratio of 0.52. At this ratio the secondary star is fully occulted by the primary, and thus the depth of the secondary transit defines this luminosity ratio.
- In order to explain the transits, I need to work with a third parameter: the linear limb brightening coefficient. Standard this is set at 0.6, but in practive it can vary wildly depending on the star. By decreasing this factor to 0, I can increase the lumiosity ratio to 0.46 and decrease the size ratio to 0.88. This still does not explain the observations: the secondary transit is to narrow and the primary transit is to shallow. The size ratio must be as small has 0.77 to explain the width of the secondary transit (red lines in figure).
Thus my current model does not work to explain these observations. I need to have other parameters that I can tune. There seems to be one assumption to many in my model.
This eclipsing binary has an eccenctric orbit as can be seen from the centers of the transits (0.0985 and 0.7561). Thus my assumption of a circular orbit does not hold. There might be a difference in apparent radii due to the orbit. A change from 0.95 to 0.77 is then needed, to explain the observations.
The difference in transit timings reveals at least a minimal eccentricity of 0.25, which corresponds to a relative distance variation between the two stars of 1.6. This might thus explain why my circular orbit does not work. So I need to refine my model to incorporate eccentricity. (Literature used Russell (1912) and Sterne (1939).
Tatooine star analysis
This a very interesting object: a double star with a planet circling around it. The excellent analysis of the previous posters seems to be the best solution. I wondered however if I would be able to expand on that by adding some numbers. Unfortunately most of the published formulae do not work here, as they all assume that the occulted star is stationary, which is certainly not the case here. So I had to invent some stuff to get to an extended explanation.

The first step involves the double star. As the transits have equal depth and are close to 50%, so both stars are assumed to be equal in size and the orbital plane (circular) has an inclination angle of 90 degrees. Thus we see the orbit edge on. The orbital period can be determined from two transits (i and i+1 - the two green transits) and is 2.976 days. Normally the width of a transitcan be used to calculate the half-major axis of the orbit. However formula 3 of Seager&Mallen;-Ornelas (2002) assumes however that the occulted star does not move, which it does in this case. Thus the observed width (0.13 days) must be doubled to get the correct one. From this the hal-major axis can be determined as 11.3 stellar radii.
To determine the movement of the planet, better timings of the transits are needed. In order to make the three extra transits more clear I subtracted the LC of the double star. This was done by shifting and overlaying an adjacent LC and then subtracting the two. The blue and green lines show where the transits were. The dots shows the results of the subtraction. And you as well that the subtraction did not succeed 100%.
Then these three transits were fitted to determine the transit times. The dermined values, such as the width (T) and impact parameter (b) have not much significance, as the formulae assume a static object. Using the start of the ingress of the first transit (day 55023.31) and the end of the egress of the third transit (day 55024.94), we can determined the speed of the planet. The model of the double star indicates where the stars are and by putting the planet next to the star, we set the position of the planet. I used the configuration indicated by @kianjin in his last animation as starting point.
This resulted in the following animation, which confirms @kianjin’s results. The first transit happens just as star 1 is turning prograde. The planet starts the transit and then star 1 speeds up and moves out under the planet. Transit 2 is when the planet passes in front of star 2. Star 2 is then retrograde, which results in a small transit width. Transit 3 happens when star 2 is retrograde.