Change of Majors
College freshmen are always told that on average, a college student will change their major at least twice (or something like that, please don't quote me on this). I always thought that I would never change my major; I liked my choice, I had always wanted to be an engineer, and I thought I knew what I wanted. But over the past year, its occurred to me that I have no idea why I decided to pick electrical engineering, and the more EE classes I take, the more I realize how little I actually like the subject; the thought of having to take another electromagnetics class doesn't exactly make me want to dance a jig, and while solid state physics can be interesting sometimes (thanks to my awesome professor), I can't see myself working with wave equations and Fermi-Dirac statistics for the rest of my life. Oh, and plus, I am no longer a math king. Really more of a math peasent then anything else, which is definetely not a good thing when I'm in a major that has so many math requirements that its only two classes short of a math minor.
I came to an epiphany several weeks ago that my major simply was not making me happy, and that it was time for me to change. I've chosen Computer Science and Engineering as my new major, although it remains to be seen whether or not my application into the Computer Science department will be accepted.
A Simple Weird Sorter
This is a little toy program written for one of my CS classes. The program takes a positive integer N as an argument and reads from stdin until it gets an EOF. The program then sorts the input using qsort, while assuming that each element to be supported is N bytes long.
Fun facts: the output from this program looks kinda cool if you do "./program_name 1 < index.html" where index.html is some large webpage.
#include <stdio.h> #include <stdlib.h> #include <errno.h> #define MEM_SIZE 100 // for the sake of ease, token length and input array are global unsigned long global_token; char * in_ptr; // comparator for qsort, // returns 1 if a is bigger, -1 is smaller, 0 if equal int comparator(const void * a, const void * b) { unsigned int i; int r_value = 0; for(i = 0; i < global_token; ++i) { if( *(i + (char*)a) < *(i + (char*)b)) return -1; else if ( *(i + (char*)a) > *(i + (char*)b)) return 1; } return 0; } // get input from stdin and save it to dynmaically allocated memory unsigned long get_input() { char* temp_in_ptr; unsigned long ar_size, n_ar_size; unsigned long max_size = MEM_SIZE; for(ar_size = 0; !feof(stdin); ++ar_size) // loop until EOF { if(max_size == (1 + ar_size)) // check if more memory is needed { temp_in_ptr =(char *)realloc(in_ptr, (size_t)(MEM_SIZE + max_size)); if(!temp_in_ptr) // returns error and exits if realloc fails { fprintf(stderr, "Error in allocating memory for input."); fprintf(stderr, "Input data may be too large.\n"); free(in_ptr); // free dynamically allocated memory exit(1); } in_ptr = temp_in_ptr; max_size += MEM_SIZE; } *(in_ptr + ar_size) = fgetc(stdin); // get next char from input if(ferror(stdin)) // check for read error { fprintf(stderr, "Error encountered in reading input.\n"); free(in_ptr); // free dynamically allocated memory exit(1); } } ar_size --; // get rid of EOF char // if string was not multiple of token length, need to make it // a multiple of token length and fill end with '\0' if(ar_size % global_token != 0) { n_ar_size = (global_token * (unsigned int)(ar_size / global_token + 1)); if(n_ar_size > max_size) // check if more memory is needed { temp_in_ptr = (char *)realloc(in_ptr, (size_t)n_ar_size); if(!temp_in_ptr) // check for error in mem allocation { fprintf(stderr, "Error in allocating memory for input."); fprintf(stderr, "Input data may be too large.\n"); free(in_ptr); // free dynamically allocated memory exit(1); } in_ptr = temp_in_ptr; } for(; ar_size != n_ar_size; ++ar_size) // fill with '\0' { *(ar_size + in_ptr) = '\0'; } } return ar_size; } int main(int argc, char** argv) { unsigned long ar_size, i; in_ptr = (char *)malloc(MEM_SIZE * sizeof(char)); if (argc < 2) { fprintf(stderr, "Must provide at least one argument.\n"); free(in_ptr); // free dynamically allocated memory exit(1); } // use strtoul() to convert char to long int // and use errno to check for error in conversion errno = 0; global_token = strtoul(*(argv + 1), NULL, 0); if(!global_token || errno == ERANGE) { fprintf(stderr, "Argument must be a positive integer.\n"); free(in_ptr); // free dynamically allocated memory exit(1); } ar_size = get_input(); // get data from stdin // sort with qsort qsort(in_ptr, (size_t)(ar_size / global_token), (size_t)(sizeof(char) * global_token) , comparator); for(i = 0; i < ar_size; ++i) //print sorted data { printf("%c", *(in_ptr + i)); } free(in_ptr); // free dynamically allocated memory return 0; }
Seven-Segment Display in VHDL
I wrote my first VHDL project last night during lab, andgot to see my design come to life when I programmed it into a Spartan3 FPGA. It was a pretty basic program, that changed a seven-segment display (like those old LED screens on old calculators) based on which switches were flipped. The four switches used were a BCD (Binary Encoded Decimal) value, so if the first and fourth switches were on and the second and third switches were off, then the BCD value would be 9 (1001). The seven-segment display would then display the value "9" if the switches were in position 1001. Fairly simple to design and program, but quite fun to play with. My VHDL code is below.
entity seven_segment is
port(
x3,x2,x1,x0: in std_logic;
a,b,c,d,e,i,g: out std_logic
);
end seven_segment;
architecture Behavioral of seven_segment is
begin
a <= NOT( x1 OR x3 OR (x2 AND x0) OR (NOT(x2) AND NOT(x0)) );
b <= NOT( NOT(x2) OR x3 OR (x1 AND x0) OR (NOT(x1) AND NOT(x0)) );
c <= NOT( x3 OR x2 OR x0 OR (NOT(x0) AND NOT(x1)) );
d <= NOT( x3 OR (NOT(x0) AND NOT(x2)) OR (x1 AND NOT(x0)) OR
(x1 AND NOT(x2)) OR (x2 AND x0 AND NOT(x1)) );
e <= NOT( (x1 AND NOT(x0)) OR (NOT(x2) AND NOT(x0)) );
i <= NOT( x3 OR (NOT(X0) AND NOT(x1)) OR (x2 AND NOT(X0) AND x1) OR
(x2 AND NOT(x1)) );
g <= NOT( x3 OR (NOT(x1) AND x2) OR (x1 AND NOT(x0)) OR
(x1 and NOT(x2)) );
end Behavioral;
Wondering
Sometimes I really wonder if I'm fit to be an engineer. Take last Friday, for example. I had my linear algebra final just last Friday, my last final of this quarter, and since I didn't do too hot on the midterms I had been spending the better part of finals week studying linear algebra. I've poured far too many hours into doing practice problems and studying my notes, so many hours, that my grades on my other finals have suffered. Come the final, I felt a little nervous but fairly confident that my endless studying would pay off.
Of course it didn't.
Confused and scared shitless would be an understatement of how I felt as I started flipping through the final. Most of the problems were proofs, asking us to prove some property of a determinant, or why the product of two matrixes of such-and-such form must assume a certain size. Some of the problems I worked through fairly easily, many of them I struggled through, and there were quite a few that I simply stared at for minutes on end. About two hours into the final, I passed through the scared stage and entered a sort of numb calmness that was strangely relaxing. But the only thing I could think of after the final, was "oh shit, I'm going to fail."
Against all possible beliefs, I got a "C" in linear algebra and so I didn't have to retake the class, unlike four other of my friends that took the class the year before. Apparently I was not the only one to suck on the final, so I didn't end up at the very end of the curve.
Granted, I used to be good at math in high school (I got a five on AP Calc AB with barely any studying, got a 130% on the final for that class, even despite the fact that my teacher was absolutely terrible.) but now I suck royally at math. Heck, I even suck at physics and electromagnetics, and I'm studying to become an electrical engineer! I find electromganetics to be amazingly dull and I've often been on the verge of falling asleep in class, something that never happened to me in high school even after a night of sleeping only a few hours. So not only do I suck at the subject material, I'm even starting to hate it, which begs the question yet again, why am I still an engineer?
I went to the library yesterday and checked out The Physics of Superheroes by James Kakalios, which I recalled my high school physics teacher briefly mentioned in class. As one might suspect from the title, the book attempts to explain how superheroes are capable of performing certain unrealistic acts, like how Electro can run up the side of a building or how Gwen Stacey died despite the fact that Spider-man caught her in his webbing before she hit the water. (I was actually quite surprised to find that Kakalios arranges the subject material in the book as one arrange a physics textbook, going from Newtonian mechanics, to thermodynamics, electromagnetism, and then quantum physics.) Kakalios's surprisingly thorough explanation of comic book superheroes has given me a small reminder just exactly why I originally wanted to be an engineer. Granted, his book is a physics textbook and isn't geared specifically towards engineering, but it still managed to remind me of how much I enjoyed learning about strange scientific theories and how science can explain things that are almost magical.
So lets just say, that I'm not entirely ready to change my major just yet.
The Inverse Ohm
It seems to me that electromagnetics has a surprisingly large amount of funky terms and units, things like retarded potentials, hysteresis curves, Teslas, Ohms, Henrys, Webers and Siemens.
The authors (Hayt and Buck) of my electromagnetics textbook have a proclivity to inserting random historical tidbits into their books, probably in the hopes that it will help students to tie together seemingly random bits of technical information. So I wasn't surprised to come across a little bit of history behind conductivity when I was reading through my textbook. What I was surprised to find, was what initially appeared to be a typo; the book stated that the units of measurement for conductivity used to be the "mho" (but was now siemens). I immediately assumed that of course, the authors had meant to write "ohm" but had mixed a few letters about. But then I remembered that ohms are a measurement of resistance and after reading a few more sentences in the textbook, I learned that the "mho" is the inverse of the "ohm."
The best part, is that the symbol for "ohms" is an omega, and the symbol for "mhos" is an upside omega!!!
Brilliant. Absolutely brilliant.
Weirdo Student
I'd like to describe a very brief dialogue that went on in my math lecture just this morning (about an hour ago). Mind you, my lecture has about 150 people in it, attendance is not taken and therefore not mandatory. For the sake of space, I shall refer to the weirdo student as WoS from this point forward.
Prof: (after having explained a new concept) Are there any questions?
WoS: (raises his hand and is called on by the professor) Its more of an aside really, are you going to be letting us out early on Friday? 'Cause I have some business to take care of.
(Seriously, who the hell says, "I have some business to take care of?" Is he referring to Flight of the Conchords? "Its Business time!" Although I seriously doubt it, WoS doesn't seem to be that kind of a person. Or perhaps WoS just really had to go to the bathroom. Anyway, I digress...)
Prof: If you have to go, just get up and go.
WoS: Oh, but you're such a great professor, I don't want to just leave.
Prof: If you have to go, just go.
At this point the professor continues on with the regular lecture.
I should probably point out, that in these large lectures, it is quite common for students to leave before lecture is over. Professors generally don't mind as long the student is discrete about it.
I'm pretty sure someone whispered that WoS was an asshole, right after the little dialogue was over. I personally would have called him a dumbass, but thats just me. WoS ended up staying for the whole lecture (maybe he peed in a cup) and as people were filing out, he said "OK, who was it that called me an asshole?" and managed to make a complete ass out of himself.
So well done WoS, well done.
AP English Literature
Because I know everyone loves reading my old high school essays, heres another one from my AP English Literature class. I received a nine (out of nine) on this 40-minute timed essay, and was the only student out of 60 to score so high (not that I mean to brag, I realize that my writing skills have grown worse afer high school).
Here's the prompt:
Read the following two poems very carefully, noting that both contain a depiction of a blacksmith. Then, in a well-organized essay, discuss how the relationship of the speaker to the blacksmith affects his attitude toward him. In your essay, you may wish to consider such things as diction, tone, figurative langauge, and style.
College Killed the High School Star
I was fairly smart and successful in high school. Albeit, I wasn't the best in my class, but I was within spitting range. When I was sixteen, I had a really nice internship that payed much more then minimum wage, and when I was seventeen, I had another really nice internship that payed slightly less but offered full medical coverage. I was the president of the Robotics team, vice-president of the Academic Decathlon team, a section leader in the jazz band, and was in so many clubs that I often had to chose between which meeting I would attend.
Now I go to a university that is recognized world wide for its academic excellence, and I'm pretty sure I've gotten dumber. Living up to my blog's name, I'm failing like I never have before.
In high school the lowest grade that I ever received was a B+, but in my past year of college I have managed to get two Cs. My grasp on Ampere's Law is rather tenuous, and my understanding of multivariable vector calculus weaker still. During the school year, I stopped attending church regularly and fell away from God. Unlike in high school, the only group that I'm still active in is marching band. This summer, I was not able to secure a high paying internship so I'll be settling for a minimum wage job and the few bucks I get for managing the marching band website.