My Dear Old Dad has a 1980 Ford F100 pickup truck that recently ticked past the quarter million mile mark. When I think of that truck I think of Saturday trips to the hardware store, I think of learning to drive, and I think of absolutely lousy gas mileage. So with the recent passing of the quarter million milestone I got to wondering, "How much money has Dad spent filling up this old rust bucket?"
The Matlab function here looks up gas price data and the consumer price index from the United States Bureau of Labor and Statistics website and estimates the present value of the total amount spent on gas over the life of the vehicle. "Estimates" is a key word here--it's not exact. I made some simplifying assumptions and I claim no expertise in economics.
year_or_range = The year you bought your car OR the years you had it.
miles_driven = The number of miles you've driven your car.
mpg = Average gas mileage of your car (miles per gallon).
An estimated present value (adjusted for inflation) of the sum of your gas receipts over the life of your vehicle. The function also creates a figure in which the price of gasoline and the present value of the cumulative sum spent on gas are plotted.
EXAMPLE 1, Dad's truck:
Question answered. My Father has spent about $50k filling up that Ford.
What about a car you sold a few years ago? Enter the dates you acquired and sold the car as an array. Consider a vehicle purchased in 2000, driven 25,000 miles, and sold in 2007.
EXAMPLE 2, Formerly-owned vehicle:
Note: Scraping the BLS ftp site takes some time. Give the script about 60 seconds to run.
Chad Greene (2021). Cost of Gas (https://www.mathworks.com/matlabcentral/fileexchange/37736-cost-of-gas), MATLAB Central File Exchange. Retrieved .
Inspired: Inflation Adjust
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!