0% found this document useful (0 votes)
4 views5 pages

01_MATLAB_Recap - Exercises

The document contains exercises for a MATLAB course focusing on data manipulation, loops, scripts, functions, and algorithm development. It includes tasks such as creating matrices, solving equations, approximating differential equations using Euler's method, generating graphs, and counting prime numbers. Each exercise outlines specific steps and hints to guide students in their coding practice.

Uploaded by

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

01_MATLAB_Recap - Exercises

The document contains exercises for a MATLAB course focusing on data manipulation, loops, scripts, functions, and algorithm development. It includes tasks such as creating matrices, solving equations, approximating differential equations using Euler's method, generating graphs, and counting prime numbers. Each exercise outlines specific steps and hints to guide students in their coding practice.

Uploaded by

snmjason727
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

Data Analysis
& Modeling

Chapter 1
MATLAB Recapitulation
- Exercises -

Lehrstuhl für Lecture – MATLAB Simulink


Flugsystemdynamik Prof. Dr.-Ing. Florian Holzapfel
1 Exercises
Exercise 1 - Manipulating Data 2

1.1 Create a 4x3 matrix of random numbers

• Extract the elements at locations (1,2) and (2,3).


• Extract the element in the lower right.
• Set every value between 0 and 0.5.

1.2 Create a diagonal matrix of size 4x4 with 3 on the diagonal.

1.3 Solve Ax = b for A = magic(3) and b = [1 2 3]T


• Compute eigenvalues of A.

Lehrstuhl für Lecture – MATLAB Simulink


Flugsystemdynamik Prof. Dr.-Ing. Florian Holzapfel
1 Exercises
Exercise 2 - For and While loops 3

2.1 Use for-loop and while-loop to find approximation of the differential equation
below, with a step size of t  0.01 second (use Euler’s method for approximation) :
dy 2
(i )  t  y 2 , y  0   1, t final  2 seconds
dt
dy
(ii )  t  y , y  0   1, t final  2 seconds
dt

Steps to do:
a) Define step size t.
b) Use for-loop or while-loop to approximate 𝑦.
c) Plot the results.

Hints: Euler‘s method


[Link]

Lehrstuhl für Lecture – MATLAB Simulink


Flugsystemdynamik Prof. Dr.-Ing. Florian Holzapfel
1 Exercises
Exercise 3 - Scripts and Functions 4

3.1 Use both script m-files and function m-files to generate a graph for the
following equations:
(i ) y  x   x 2 , for  1  x  1
2
 e x 
(ii ) y  x   2  sin 2  x    0.2, for  1  x  1
 x 1 

Steps to do:
a) Create script m-files for both equations.
b) Create function m-files for both equations.
c) Plot the results.

Lehrstuhl für Lecture – MATLAB Simulink


Flugsystemdynamik Prof. Dr.-Ing. Florian Holzapfel
1 Exercises
Exercise 4 – Algorithm developoment 5

4.1 Write codes to count the prime numbers between lower and upper bounds and
show elapsed times to run these programs.

Steps to do:
a) Create script m-files (save it as “primzahl.m”) to calculate the prime
numbers at given input range [lower, upper] using conventional MATLAB
syntax (for, if, etc.).
b) Fill your code with a stopwatch timer function (tic and toc) to measure
elapsed time.

Lehrstuhl für Lecture – MATLAB Simulink


Flugsystemdynamik Prof. Dr.-Ing. Florian Holzapfel

You might also like