Numerical Analysis Lab 1
Numerical Analysis Lab 1
Experiment # 1
Objective: Introduction to MATLAB and Numerical Analysis Basics
Overview: MATLAB interface, command window, script editor, and workspace.
Command Window: This is the main area where we can type and execute individual commands.
It's ideal for quick calculations, testing small pieces of code, and interacting directly with
MATLAB.
Script Editor: This is where we can write, save, and run multiple lines of code, known as scripts.
Scripts are saved with a .m extension and allow us to organize code in a structured way.
Workspace: The Workspace shows all the variables we’ve defined or imported. We can view each
variable’s size, data type, and value. This helps us keep track of our data and see the results of our
calculations.
Basic Commands: Variables, arithmetic operations, and built-in functions (e.g., sin, cos, exp).
In MATLAB, we can perform a variety of calculations and define variables easily. Here are some
common operations:
We can name variables using letters, numbers, and underscores, but variable names cannot start
with a number.
• Addition: +
• Subtraction: -
• Multiplication: *
• Division: /
• Exponentiation: ^
Example:
% Define variables
a = 10;
b = 5;
Built-in Functions: MATLAB has a large library of built-in functions for mathematical
operations. Examples:
Vectors and matrices are fundamental to MATLAB and are easy for us to work with:
• Defining a Vector:
o Row vector: v = [1, 2, 3, 4];
o Column vector: v = [1; 2; 3; 4];
• Defining a Matrix:
Plotting: Basic 2D plotting (e.g., plot, xlabel, ylabel, title) for visualizing functions and data.
• Creating a Plot: To plot a function or data, we use the plot command. For example:
• Labels and Titles:
o We use xlabel and ylabel to label the x and y axes.
o We use title to add a title to the plot.
Example: