Worksheet 3

Workspace Setup

Ensure your MATLAB path is set to

<INSTALLDIR>/i2sc_worksheets/Worksheet3

where <INSTALLDIR> is the directory where you extracted the course content (see the Getting Started page)

1. Piecewise Linear Interpolation

In this exercise you will read in a lift curve and store it in an array. You will then perform linear interpolation to find the lift at any chosen angle, and the angle needed for a chosen lift. The lift data is shown below and is contained in the file data/liftcoeff.txt.

Lift curve slope stored in data file.
Lift Data

Complete the following tasks in the supplied file problem_1.m

  1. Write a function with the signature [alphas,Cls] = readData() to extract data from the data file. You may find the code snippet C = textscan(fid,'%f %f','HeaderLines',1); useful.
  2. Write a function with the signature [Cls] = interpCl(alpha) to perform piecewise linear interpolation to find the interpolated lift coefficient for the user-specified angle alpha
  3. Ensure the function you generated in step two works for an array input e.g. alphas = 0:0.1:1;
  4. Extend your script to create a plot showing both the data points, and the `curve’ produced from the linear interpolation (you will need to perform linear interpolation for a large number of angles and plot the resulting response).

2. File Input

When an aerofoil is placed in flow (as shown in Figure), pressure forces, that act normal to the surface, can be measured at any given point.

Aerofoil Forces.
Aerofoil Forces

The Task

There are three files in the data folder which contain pressure values around a NACA23015 aerofoil (calculated using the XFOIL program) at \(0^{\circ}\), \(5^{\circ}\) and \(10^{\circ}\) angles of attack

  • \(0^{\circ}\) this is stored in the file naca23015_00degs.txt
  • \(5^{\circ}\) this is stored in the file naca23015_05degs.txt
  • \(10^{\circ}\) this is stored in the file naca23015_10degs.txt

Complete the following tasks in the supplied file problem_2.m

  1. Create a function with the signature [x,cp] = readCpData(filename); which reads the data from the data file.
  2. produce a single graph of \(-C_P\) against \(x/c\) with all three angles of attack plotted (use different line styles and a legend to distinguish the data sets).

3. Potential Flow

At a location, denoted by \((x,y)\), an example potential flow has a velocity vector \((u,v)\) which is given by:

\[\begin{aligned} u &= 1 + \frac{x}{2\pi(x^2+y^2)} \\ v &= \frac{y}{2\pi(x^2+y^2)} \end{aligned}\]

Complete the following tasks in the supplied file problem_3.m

  1. Write a MATLAB function with the signature [u,v] = flowVelocity(x,y) which returns the flow velocity at the point \((x,y)\)
  2. Edit the function to ensure it accepts an array as an input e.g.
    x = -1:0.1:1;
    y = -1:0.1:1;
    [u,v] = flowVelocity(x,y);
    
  3. Create a single plot in the range \(x \in \{-1,1\}\), \(y \in \{-1,1\}\) containing both:
    1. A contour plot of the velocity magnitude (\(U=\sqrt{u^2+v^2}\))
    2. A quiver plot of the velocity, with quivers spaced 0.05 apart in both the \(x\) and \(y\) directions
  4. Save the figure in the .fig format so we can edit it later. Save the file at bin\potFlow.fig. Hint: use the savefig method.

4. Streamlines in Potential Flow

A streamline through a flow field can be calculated using numerical integration. The method used here is a first order Euler method. Given a current location at the current time level \((x_{old},y_{old})\), the next location \((x_{new},y_{new})\) is given by:

\[\begin{aligned} x_{new} &= x_{old} + u_{old}\Delta t \\ y_{new} &= y_{old} + v_{old}\Delta t \end{aligned}\]

where \(u_{old}\) and \(v_{old}\) are the velocity components at the current location. A basic schematic is shown in Figure.

Streamline schematic.
Streamline schematic

The Task:

Complete the following tasks in the supplied file problem_4.m

  1. Write a MATLAB function with the signature [u] = flowVelocity(p) which returns the flow velocity \(\mathbf{u}\) (a 2xN vector, where row one is the \(u\) and row 2 is the \(v\) component), at the points \(\mathbf{p}\) (a 2xN vector, where row one is the \(x\) coordinate and row 2 is the \(y\) coordinate). Use the same equation as that in section 3.
  2. Write a MATLAB function with the signature [p,t] = getStreamline(p0,dt) which returns the path of a streamline starting the point p0 (a 2x1 vector). Use the Euler method described above, where the argument dt is the timestep to use.

    Use your function flowVelocity(p) inside this function to calculate the velocity at a given point

  3. Starting at the point (-1,0.5), plot the streamlines for each of the following timesteps dts = [2,1,0.5,0.1,0.01]. Comment on the difference, and choose a suitable timestep to use moving forwards.
  4. Plot the streamline starting at (-1,0).

    This point will likely cause an error in your code, or ‘hang’ indefinitely. As a first fix try adding a maximum number of timesteps to you function getStreamline. What is the physical significance of where this streamline ‘ends’? Can you think of a better stopping criteria?

  5. Load the figure you created in section 3 (e.g. the .fig file you saved - Hint help openfig). Plot the streamlines starting at x = -1, y = -1:0.25:1 onto this figure.

In general, it is recommended that you avoid the use of the streamline function in MATLAB


Copyright © 2025 Fintan Healy. Distributed by an MIT license.