MATLAB Programming For Numerical Computations
MATLAB Programming For Numerical Computations
TO MATLAB PROGRAMMING
Lec 1.1: MATLAB Basics
Dr. Niket Kaisare
Department of Chemical Engineering
IITMadras
Indian captain, Mahendra Singh Dhoni, hits a ball with initial velocity of 35
m/s and angle of 45. If the boundary is at a distance of 75 m, will he score
a six?
Setting up the problem:
!"#$ = 35; *+ = !"#$ cos //4 ; !+ = !"#$ sin //4
4 5 = *; 6 5 = !
* 5 = 8*; ! 5 = 9;
Result
MATLAB Code
%% Define Parameters and Initial Conditions
param.g = 9.81; % gravitational acceleration
param.kappa = 0.006; % air drag coefficient
u0 = 35*cos(pi/4);
v0 = 35*sin(pi/4);
%% Animating results
exitCode = ballAnimation(tOut,XOut);
MATLAB Code: Main Code Blocks
%% Define Parameters and Initial Conditions
Output block
figure(1);
plot(XOut(:,1),XOut(:,2),'bo');
xlabel('x (m)'); ylabel('y (m)');
%% Animating results
exitCode = ballAnimation(tOut,XOut);
MATLAB Code: Key Parts
%% Define Parameters and Initial Conditions
param.g = 9.81; Comment
u0 = 35*cos(pi/
Assignment
(Math) Expression
Calling a function
plot(XOu
Calling a function
MATLAB Code
%% Define Parameters and Initial Conditions
param.g = 9.81; % gravitational acceleration
param.kappa = 0.006; % air drag coefficient
u0 = 35*cos(pi/4);
v0 = 35*sin(pi/4);
%% Animating results
exitCode = ballAnimation(tOut,XOut);
Basic Data Types
Assigning variables
Arrays / Matrices
Suppress echo