Day 03 - Getting Started with VS Code
Today we'll set up VS Code for scientific computing and practice numerical differentiation.
![]()
Today’s Goals#
After this session, you should be able to:
Set up VS Code for Python scientific computing
Use Jupyter notebooks in VS Code
Perform numerical differentiation using finite difference methods
Compare numerical results with analytical solutions
Step 1: Download VS Code#
Go to: https://code.visualstudio.com/download
Choose your operating system:
macOS: Universal download (Intel + Apple Silicon)
Windows: User Installer
Linux: .deb, .rpm, or .tar.gz
The download is ~200 MB and takes just a minute or two.
Step 2: Install VS Code#
On macOS:
Open the downloaded
.zipfileDrag
Visual Studio Code.appto ApplicationsLaunch from Applications
On Windows:
Double-click the
.exeinstallerFollow the wizard (default settings are fine)
VS Code launches automatically
Step 3: Install Required Extensions#
Click the Extensions icon (4 squares) on the left sidebar
Or press
Ctrl+Shift+X(Windows/Linux) orCmd+Shift+X(Mac)
Install these two extensions:
Jupyter by Microsoft
Python by Microsoft
Click Reload when prompted.
Step 4: Verify Python#
Open VS Code’s Terminal: View → Terminal (or Ctrl+`)
Type:
python --version
or
python3 --version
You should see something like Python 3.10.0 or newer.
If not, install Python from: https://www.python.org/downloads/
Download Today’s Activity#
Open the notebook for today’s activity:
https://dannycaballero.info/phy321msu/resources/vscode-setup-numerics-activity.html
Or find it in the course website under Resources.
Download the .ipynb file and open it in VS Code.
Libraries We’ll Use#
import numpy as np # Numerical computations
import matplotlib.pyplot as plt # Plotting
import pandas as pd # Data manipulation
Run the first code cell to load these libraries.
If you get an error, you may need to install them:
pip install numpy matplotlib pandas
The Physics: Numerical Derivatives#
In experiments, we measure positions at different times.
To get velocities or accelerations, we numerically differentiate our data.
This is the forward difference method.
Finite Difference Methods#
Three common methods:
Forward: \(f'(x_i) \approx \dfrac{f(x_{i+1}) - f(x_i)}{\Delta x}\)
Backward: \(f'(x_i) \approx \dfrac{f(x_i) - f(x_{i-1})}{\Delta x}\)
Central: \(f'(x_i) \approx \dfrac{f(x_{i+1}) - f(x_{i-1})}{2\Delta x}\)
Central difference is more accurate but uses both neighboring points.
The Synthetic Data#
We’ve generated position data for a ball tossed with air resistance:
Run the data generation cells in the notebook to create:
t- time array (seconds)x- x-position array (meters)y- y-position array (meters)
Your Task#
Using only finite difference methods:
Compute and plot the numerically-derived velocities (\(v_x\), \(v_y\))
Compute and plot the numerically-derived accelerations (\(a_x\), \(a_y\))
Compare your numerical derivatives with the “true” values
What do you notice about the accuracy?
Work through the notebook with your neighbors!
Hints#
To compute velocity from position:
dt = t[1] - t[0] # time step
vx = (x[1:] - x[:-1]) / dt # forward difference
Note: Your derivative arrays will be one element shorter than the original!
To plot against the right time values:
plt.plot(t[:-1], vx) # use t[:-1] not t
Exporting Notebooks to PDF#
For homework submissions on Gradescope:
Option A: VS Code Extension
Install “Jupyter PDF Export” extension
Right-click notebook → Export as PDF
Option B: Command Line
jupyter nbconvert --to pdf your_notebook.ipynb
Option C: Print to PDF
Use
Ctrl+P/Cmd+P→ Print
Reminders#
Homework 1 is due next Friday (late after Sunday)
Help sessions start next week
Fill out the help session poll
Complete the student information survey
Get Started!#
Download the notebook from the course website
Open it in VS Code
Work through the cells
Complete the analysis task with your neighbors
Ask questions as you go!