Thursday, March 31, 2016

MATLAB Introduction

MATLAB is yet another programming language, frequently known as the "glorified calculator."  Code some equations, assign numbers, and MATLAB runs like magic!

2.1 Fibonacci:

A Fibonacci sequence is a list of numbers adding the previous consecutive numbers.  We coded the Fibonacci equation into MATLAB and set n = 10.  The result for adding the first 10 numbers in the Fibonacci sequence is 55.


2.3 Car_Update:

In this problem, there are two car companies: one in Albany, one in Boston.  In the beginning of the year, each location has 150 cars.  Each week, 5% of cars go into Boston from Albany and 3% of cars are dropped off in Albany from Boston.

anew and bnew are the equations for number of cars in each car company.  Afterwards, we set anew and bnew to a new variable a and b and rounded them to a whole number using round().  In the two equations:

  • a, b: constants of 150 cars
  • % cars coming in 
  • % cars leaving
We then assigned the value for a and b in the bottom.














3.1 Car_Loop:

This exercise takes the script from Car_Update and runs it 52 times in a for loop.














3.2 Car_Loop with Plot:

Taking Car_Loop, we plotted the values of the number of cars in each location to the different week numbers.  We put the script for car_update in our car_loop_plot script and it works the same if they are in the same folder.  You can assign different colors and shapes for each plot on the graph.

















The graph on the left is when a and b are initially 150.


The graph on the right is when a and b are initially 10000.













3.5 Fibonacci2:

Going back on the Fibonacci1 script, in this exercise, we are to re-code the equation to where
F(i) = F(i-1) + F(i-2).  In the for loop, we set the lowest number in the sequence to start at 3 because since F(1) and f(2) equal 1 and would not initially work in the equation.




















4.6 Fibonacci2_Ratio with Plot:

Using what we coded in Fibonacci2, we coded the equation for the ratios of two consecutive fibonacci numbers and proceeded to plot the ratios in the equation g(i).  If we wrote "fibonacci2" in fibonacci_ratio_plot, there would be a for loop within a for loop, which will not work.  Instead, we wrote out the equation and the two constants.





















In the x axis, the ratios of the two consecutive numbers in the fibonacci sequence.

In the y axis, the term in the fibonacci sequence.














2 comments:

  1. I think it was really smart of you guys to start at 3 so that F(1) and f(2) work in the equation.

    ReplyDelete
  2. I really like your little intro at the beginning of the blog. I also like the format of your post, it really helps to make your thought process flow together.

    ReplyDelete