Docsity

Aerospace Practicum: MATLAB Introduction and Exercises, Study notes of Aerospace Engineering

Toggle sidebar
bg1
1
Aerospace Practicum
Introduction to MATLAB
In-Class Practice Exercises
Complete these problems if you finish all of the in-class demonstrations before the laboratory is
over. If you do not get to these in class, take a look at them during your own time, but you need
not hand in these exercises with laboratory homework assignment #2.
Notes:
• First, remember that you are learning MATLAB for the first time. Like any new piece of
software, it will take you a while to figure out how to use the program and it will
certainly take a while before you have mastered the full capabilities of what the program
can do. Please be patient with it; once you get the hang of how to use MATLAB, you will
have a very powerful tool at your disposal that you can use throughout your career.
• Remember that any time you forget what a MATLAB command does you can simply
type help and the name of the command. For example, if you need a refresher on how the
plot command works, you can type: help plot
• The programmers of MATLAB apparently have a sense of humor. For the answers to all
your life’s questions, at the command prompt type: why
1. The equation for a circle in Cartesian coordinates is given by:
222 Ryx =+
1.1
Where R is the radius of the circle and x and y are coordinates. Plot a perfect circle with radius
of unity using:
a) MS Excel (be careful: you want your plot to look like a perfect circle, not an ellipse. This
will require some manipulation on your part, it’s not that easy!)
b) MATLAB using Cartesian coordinates. Hint: after you have generated your circle you
can make it a perfect circle by making the scale of the axes equal by typing: axis equal.
c) MATLAB using the polar function. Type: help polar, to explore this function. See if you
can use this function to generate a perfect circle.
2. Examine the following script, which will give you some practice in 3-D plotting and the use
of for loops: % Program to generate a helix
k=0;
for t=[0:pi/50:10*pi];
k=k+1;
X(k)=sin(t);
Y(k)=cos(t);
Z(k)=t;
end
% 3D Plot - helix
Docsity.com
pf2

Partial preview of the text

Download Aerospace Practicum: MATLAB Introduction and Exercises and more Study notes Aerospace Engineering in PDF only on Docsity!

Aerospace Practicum Introduction to MATLAB In-Class Practice Exercises

Complete these problems if you finish all of the in-class demonstrations before the laboratory is over. If you do not get to these in class, take a look at them during your own time, but you need not hand in these exercises with laboratory homework assignment #2.

Notes:

  • First, remember that you are learning MATLAB for the first time. Like any new piece of software, it will take you a while to figure out how to use the program and it will certainly take a while before you have mastered the full capabilities of what the program can do. Please be patient with it; once you get the hang of how to use MATLAB, you will have a very powerful tool at your disposal that you can use throughout your career.
  • Remember that any time you forget what a MATLAB command does you can simply type help and the name of the command. For example, if you need a refresher on how the plot command works, you can type: help plot
  • The programmers of MATLAB apparently have a sense of humor. For the answers to all your life’s questions, at the command prompt type: why
  1. The equation for a circle in Cartesian coordinates is given by:

x^2 + y^2 = R^2 1.

Where R is the radius of the circle and x and y are coordinates. Plot a perfect circle with radius of unity using: a) MS Excel (be careful: you want your plot to look like a perfect circle, not an ellipse. This will require some manipulation on your part, it’s not that easy!) b) MATLAB using Cartesian coordinates. Hint: after you have generated your circle you can make it a perfect circle by making the scale of the axes equal by typing: axis equal. c) MATLAB using the polar function. Type: help polar, to explore this function. See if you can use this function to generate a perfect circle.

  1. Examine the following script, which will give you some practice in 3-D plotting and the use of for loops: % Program to generate a helix k=0; for t=[0:pi/50:10*pi]; k=k+1; X(k)=sin(t); Y(k)=cos(t); Z(k)=t; end

% 3D Plot - helix

Docsity.com

plot3(X,Y,Z) xlabel ('x') ylabel('y') zlabel('z') title('Helix')

Notice the use of the ‘for’ loop and the counter k. Once you have typed this code in, run the code and save it as an m-file, named helix.m

  1. MATLAB is also highly versatile in that it lets you, the user, create your own custom functions. To get a feel for this idea type: help function To get a further idea of what is going on with developing your own function, try the following script:

function [Dir]=direction(m) lat=m(1); long=m(2); c1=cos(latpi/180); s1=sin(latpi/180); c2=cos(-longpi/180); s2=sin(-longpi/180); Dir=[c1s2,-s1,c1c2]';

This short script creates a new function called ‘direction’ that takes a two variable input, which are the latitude and longitude of a location. For example, Melbourne is at latitude of 28.1º and longitude of -80.6º. This corresponds to an input of x=[28.1, -80.6]. The function then converts this to a direction output. The direction output is an ijk unit directional vector relative to the center of the earth. Try this function by typing in the given x input and then typing: direction(x).

Docsity.com