0% found this document useful (0 votes)
52 views2 pages

Basic Programming in MATLAB

1) The document describes using MATLAB to simulate the trajectory of a ball hit at an initial velocity and angle to determine if it will score a six. 2) The simulation is set up using ode45 to solve the equations of motion with air drag, and the results are plotted and animated. 3) Basic MATLAB operations are also described such as defining matrices and vectors, using semicolons, and different types of loops.

Uploaded by

Himalaya Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views2 pages

Basic Programming in MATLAB

1) The document describes using MATLAB to simulate the trajectory of a ball hit at an initial velocity and angle to determine if it will score a six. 2) The simulation is set up using ode45 to solve the equations of motion with air drag, and the results are plotted and animated. 3) Basic MATLAB operations are also described such as defining matrices and vectors, using semicolons, and different types of loops.

Uploaded by

Himalaya Gaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic Programming In [tOut, XOut] = ode45(@balltrajectoryfun,

tspan, X0, [], param);


MATLAB
%%displaying the results
 Book by Laurene Figure(1);
Plot(XOut(:,1), XOut(:,2), ‘bo’);
Fausett Xlabel(‘x(m)’); ylabel(‘y(m)’);

%%animating results
Exitcode = ballAnimation(tOut, Xout);
To start a MATLAB editor we have to give
a command edit space followed by the file
name.
This will be the blank file.

Basic Data Types


Matlab easily works with arrays
MATLAB programming Scalars, vectors and arrays
Example Assigning variables
Indian captain, Msd hits a ball with initial Row vs column vectors
velocity of 35m/s and angle of 45 degree. Arrays/matrices
If the boundary is at a distance of 75m, Variable are case-sensitive
will he score a six.
How to do it in MATLAB Command
%%setting up a problem Window
V_net = 35m/s ; U_o=Vcostheta
where theta is pie/4 and V_o = >> a = 4. Gives a = 4
Vsintheta >> b = [1:5]. Gives b = 1 2 3
4 5. (an array from 1 to 5)
MATLAB Code >>c = [1, 2; 7, 4]. Gives c = 1 2
%%Define parameters and initial ( a 2x2 martix)
conditions 7 4
Param.g = 9.8; % gravitational acceleration
Param.kappa = 0.006. %air drag
coefficient >>d = [1;2;3;4]. Gives a column
U_o = 35*cos(pi/4); %x-direction velocity vector with values 1,2,3,4.
V_o = 35*sin(pi/4) ; %y-direction velocity
Comma are going to separate
various elements in a particular
%%setting up and solving the problem
rows where as semicolon is going to
X0 = [0; 0; U_0; V_0]; %starting position
is the origin separate elements in various rows
tSpan = [0,20]; %simulation time
When we end a command with a 2.While LOOP
semicolon then echo is being
suppress i.e. variable is assign to the
Command
function. (matlab turant result shoe While i<10
nhi karega ) <statement 1>;
.
To clear a variable from command
window, just write clear space .
variable name <statement n>;
I=i+1;
Array Operation In MATLAB
End
To write identity matrix of size 3x3
write When to use for loop?
>> c = eye(3) For loop is used when a set
Transpose of matrix = use an of operations are to be
apostphi ‘ repeated a specific number
Getting any particular element of a of time.E.g; find first 10
any size matrix, let us take a 3x3
matrix F and we have find element
terms of Fibonacci series
(2,1) i.e. matrix name( row no. , Find factorial of number n
column no)
F(2.1) give that element

Various LOOP in MATLAB


1: For Loop
Command
For i=1:10
<statement 1>;
.
.
<statement n>;
End

You might also like