**School of Engineering **

**Computational Engineering Analysis AERO2463 **

**Assignment 4**

**4.1 Curve Fitting - Polynomial Fitting of Data **

**4.2 Finite Differences and Differential Equations **

**School of Engineering **

**Computational Engineering Analysis - AERO2463**

**Assignment 4.1**

**Curve Fitting - Polynomial Fitting of Data **

**Assessment: **

The MATLAB Assignment 4.1 is worth 5%.

**Objectives: **

Generate curves by fitting data using polynomials

**Submission Instructions: **

- There are two m-files provided to you on Canvas. One is the template for the function file you are to submit and the other is a script file that you should use to test your function file (please do not submit the script file used for testing your function).
- Submit a single function m-file via Canvas before submission due date specified above.
**Note**that the Last Name and Student ID are required as a comment line at the beginning of the m-file, but**after the function header**.- The m-file submitted on Canvas should be named as:

*LastName*_*StudentID*_*polynomial_fitting*.m (write your function in this one)

- Do not zip any files.
- Failure to submit before the deadline will require a reasonable explanation and approval from the Course Coordinator before any later submission can be accepted.
- RMIT late assignment submission policy will apply (10% deduction of marks for each day delay).
- Use the Special Consideration process for any submission later than one week.
- Submit only the files related to the Assignment 4.1.

**Background **

When dealing with data from experiments or computations, the data will be discrete and not have uniform spacing. Fitting the data within a polynomial can help to predict outputs and to deal with the data in further calculations.

The aim of fitting your discrete data to a polynomial is to be able to predict a value of the dependent variable in terms of the independent variable for those values which do not have corresponding discrete data. Depending on the relationship of the variables, polynomials of different orders should be used to find a good fit between the polynomial and the real data. In the figure shown below, real measurements of liquid water density were taken in increments of 10 °C and several polynomials were calculated using polyfit()to see the correlation between them and the discrete data.

After a polynomial is obtained, we can try to interpolate or extrapolate y-values for any x-value. Be careful if you are extrapolating outside the boundaries of your discrete data, the polynomial could fit well inside your data, but maybe it does not represent well the reality outside them. What is the density of liquid water (pressurized) for temperatures greater that 100°C? In the figure above, we can try to extrapolate them, but we do not know if the physical phenomena will be still fitting our polynomials.

**Task **

Your task is to write a function which takes two vectors, *x *(independent variable) and *y *(dependent variable), and fits polynomials from order 1 (linear relation) up to order 10 (or the maximum order possible for the data size). The function should plot the *x* and *y* data with markers (no line) and plot each fitted polynomial (with lines), all on the same plot axis. In a separate figure (or in separate plots within one figure using subplot), plot the interpolated/extrapolated *y* value for a given *x*-point defined by the user.

**Coding Requirements **

- Use the MATLAB built-in function
.*polyfit* - You should
**not make any sub-functions**inside the function. - Ensure the x and y data given to the function have the same length. If it is not the case, the function
**MUST**use the error() function to give the user an error message and exit. - There must
**NOT**be any user interaction within the function. - To fit a function with a polynomial of an
**order**(also called**grade or degree) “n” there must be at least “n+1” points**. Your code**MUST**detect if the number of points is not sufficient enough and show an error message before trying to calculate wrong polynomials. - The user will enter the x and y vectors to the function from the script, and it will also specify a point “x2” which the function will use to extrapolate its value y(x2) using all the polynomials calculated.
- You should create extra
*x-*points in your function to make the polynomial line plots smoother using more points. - If the given data fits exactly a polynomial of an order lower than 10, your function
**MUST NOT**plot the polynomials of a greater order. You could use a tolerance to test this.

*Hint:* In order to fulfill requirement number 8, you should compare your coefficients with a certain tolerance (e.g 10e-6) if you calculate your polynomial, and from certain coefficient all the higher order coefficients (beyond it) are lower than the tolerance, you may assume that it is a perfect fit for a polynomial, excluding those higher order coefficients (i.e. they are equal to zero).

**Examples **

**Example 1 **

In this first example, the data fits exactly an order 2 polynomial, therefore the code will only plot two polynomials (order 1 and 2)

The user will produce a call to the function in the workplace such as:

In this case, the function output will produce two plots. The first one is the polynomial fits with the original data. As the polynomial of order 2 fits exactly the function, only 2 polynomials have to be plotted.

The second plot output contains the predictions at position x2 (x-axis is polynomial order, y-axis is the predicted y value). You have to plot only the number of predictions of the plotted polynomials. As in this case the original data was a perfect x^2 relation, we expect all polynomials of this order or greater to perfectly fit the data and extrapolate the same value. In this subplot you can choose between plotting the guesses of all the polynomials or plot only those guesses for the polynomials shown in the previous figure.

**Example 2. **

In this case, the fitting will not be perfect with any polynomial, and the code will have to plot all the required polynomials:

The two plots produced will look like the ones below:

The small amount of scatter in the data leads to dramatically different predictions of the data at an x value of 2.5 (the last known data point was 2.3).

The lesson to be learnt here is: **Never extrapolate data with a polynomial unless you know the data is governed by a polynomial of a given order. **

When creating software it is ** very important **to ensure your program satisfies the requirements.

Requirements are often very specific as your software may need to interact with user and/or other software components in a very specific way.

Please heed the following warning and ensure your program meets all the requirements described herein before submitting it.

**Assessment **

Correctly plots fitted polynomials as specified 60%

Correctly plots interpolated/extrapolated y-value for user input x-value in separate plots 20%

If data set mathches a polynomial, higher-order polynomials are not fitted or plotted 20%

Code does not produce error message if x and y are of different size. -20%

Code does not produce error message applied to data set with less than 11 points. -20%

Appropriate deductions for not meeting requirements (e.g. wrong file name) -20%

**IMPORTANT: HINTS (DOs and DON’Ts) **

**DO NOT PLACE CODE ABOVE YOUR FUNCTION DEFINITION**. This is mixing a script and function and cannot be done. The user will pass the data they wish to use to the function via the input arguments!

**DO NOT STORE SOMETHING TO X, X2 OR Y IN YOUR FUNCTION**. If you store values in x, x2 or y in your function, then it will overwrite what the user specified for x, x2 and y.

**TEST YOUR CODE**: Your code may fit well a provided set of data (but it may not fit for another data set). Make up your own data (that you know the answer to) and test that your function returns the correct results.

**TUTORIALS**: Please do the learning exercises in the tutorials. They will teach you the skills necessary to do this task.

**School of Engineering **

**Computational Engineering Analysis - AERO2463 **

**Assignment 4.2**

**Finite Differences and Differential Equations **

**Assessment:**

The MATLAB Assignment 4.2 is worth 5%.

**Objectives: **

Solve a mechanics problem to calculate the displacement, strain and stress in a 1D elastic structure using the Finite Difference Method.

**Submission Instructions: **

- You should submit ONE function m-file.
- In the m-file code, you MUST write your name and student ID as a comment line in the mfile.
- Use the templates provided on Canvas.

The m-file should be named as:** Last Name_Student ID_FiniteDifference.m **(write your function in here)

**Please note:** You will have to include the same function name as the above file name inside your function file to run it.

- Do not zip the file.
- Failure to submit the assessment solution file through Canvas before the end of submission date and time will need special consideration approval from the coordinator to re-submit (with reasonable explanation).
- In that case, RMIT policy of late assignment submission will apply (10% deduction of marks for each day delay).
- Another m-file called
**m**is provided to try and call your function. Do NOT submit this file.

*AERO2463 Computational Engineering Analysis: Assignment 4, 2018*

**Problem: **

Consider the example of a compression or tensile mechanical test. A sample one-dimensional rod or beam type structure is placed in the tensile test machine. One end is fixed whereas the other end is subject to an imposed displacement. This displacement generates strains and stresses in the structure.

We consider the 1D configuration described by the figure below:

We consider a static problem, where a specific displacement is imposed on a simple 1D rod structure. One end of the rod is fixed (zero displacement) at *x=*0, and a displacement of value D is imposed at the other end at *x=L*.

**Objective: The aim is to determine the displacement field in the structure for a given displacement at the end point, as well as the strain and stress field, using a second order Finite Differences (FD) method. **

The strain ( ) relation is given by the following equation for the current 1D problem:

The stress is then computed as:

where *E* is the Young’s modulus.

The 1D equation of equilibrium in the absence of an external force is given by. 0

which in 1D corresponds to

This last equation needs to be solved with the Finite Differences method. The structure of length *L* will be discretized (divided) into *N _{x}* elements (segments), as shown in the figure above. Here are some hints describing the intermediate steps required to solve this problem numerically.

*AERO2463 Computational Engineering Analysis: Assignment 4, 2018*

- Using the expansion in Taylor series, write the
**central difference scheme**for the second order partial derivative ⁄ . This will be true for interior nodes 2 to*N*-1. Special care must be taken for the first and last nodes._{x} - For the first node (
*x=*0) the displacement is labeled. The value of this displacement is known since it is a**boundary condition,**0. We account for the first term as follows:

- For the last node, (
*x=L*) the displacement is labeled. This displacement is also known because it is the second**boundary condition**: . Similarly, we account for the last term as follow:

- You now have a general scheme for node ∈ 2, 1 , and a simple relation for the first node 1, and the last node . That is all you need to construct a linear system, where
**U**is the unknown vector of displacement to be computed, is a square matrix defined from the FD scheme above, and**B**is a vector containing the imposed displacement.

Construct a square matrix of dimension *N _{x }× N_{x}* to write the linear system .

**Then, you can start programming in MATLAB. **

- In your MATLAB function
**Last Name_Student ID_FiniteDifference.m**, you need to:- Discretize the geometry (divide
*L*in*N*-1 segments or cells, to have_{x}*N*nodes)._{x} - Construct the matrix (start with a zeros (of size
*N*) matrix and use a_{x}*for loop*to modify the non-zero terms). First and last columns need to be defined separately to incorporate boundary conditions. - Construct a vector
**B**to store the imposed displacement. - Solve the problem to obtain the displacement
**U**by inverting the linear system. Plot the displacement field along the structure. - Compute the strain from the displacement. Plot the strain along the structure.
- Compute the stress and plot it along the structure. What do you observe and conclude?

- Discretize the geometry (divide

**Your function must produce 3 plots (displacement, strain and stress along the length of the rod structure) and return 2 vectors X and U, respectively, for the discretized domain and the displacement. **Since the strain and stress are calcualted for each 1D segment (element), these can be plotted against the displacement at the upper node for that corresponding segment.

**Assessment Criteria **

- Correct implementation of the FD scheme for displacement 60%
- Correct computation of strains and stresses 20%
- Correct plotting 20%
- Renaming function, inputs or outputs -25%
- Using a built-in ODE solver -25%

- Homework Help Australia
- Assignment Help Sydney
- Assignment Help Brisbane
- Diploma Assignment Help Australia
- Holmes University Assignment Help
- Write My Assignment for Me Australia
- Online Assignment Help in Australia
- Statistics Assignment Help Australia
- Event Management Assignments Help
- Public Health Assignment Help
- Child Care Assignment Help
- Management Assignment Help
- ACCT6003 Financial Accounting Process Assessment
- Accounting Assignment Help
- Finance assignment help Australia
- Statistics Assignment Help Australia
- Taxation Assignment Help
- Computer Science Assignment Help
- Cost Accounting Assignment Help
- Financial Accounting Assignment Help
- Financial Management Assignment Help
- Writing Assignment For University
- Operations Management Assignment Help
- Construction Management Assignment Help
- Computer Network Assignment Help
- Arts and Architecture Assignment Help
- Biotechnology Assignment Help
- Engineering Assignment Help
- Management Assignment Writing Help
- MIS771 Descriptive Analytics and Visualisation
- Kent Institute Assignment
- Laureate International Universities
- Tafe NSW
- Yes College

- HBS108 Assignment Task 1: Sourcing, Identifying and Evaluating Evidence
- HSW111 Assessment task two: Application of theory to a case study
- ACCT19060 Management Accounting
- ACCT19060 concepts of managerial Accounting
- MIS171 Business Analytics Assignment 1
- MIS782: Value of Information
- SIT103 – Data and Information Management T2, 2019
- SIT103 Database and Information Retrieval
- SIT123: Data Capture Technologies Lab 1
- SIT123: Data Capture Technologies Lab 2
- SIT123: Data Capture Technologies Lab 3
- SIT282 Trimester 1 Assignment 1 Donald Price
- SIT718 Real World Analytics
- E1144 Certificate III in Individual Support Assessment 2.1
- E1144 Certificate III in Individual Support Assessment 2.2
- E1144 Certificate III in Individual Support Assessment 2.3
- CHCAGE001 Facilitate the empowerment of older people
- CHCCOM005 Communicate and CHCLEG001 Work Legally Ethically
- CHCCCS015 Provide individualized support
- CHCAGE005 Provide support to people living with dementia
- CHCDIS003 Support community participation and social inclusion
- CHCCCS023 Support Independence & CHCDIV001 Diverse People
- BSBMGT608 Manage innovation and continuous improvement Task 1
- BSBMGT608 Manage innovation and continuous improvement Task 2
- BSBMGT608 Manage innovation and continuous improvement Task 3
- BSBINM501 Manage an information
- CSE3OSA Assignment 2019
- BSBMKG501- Identify and Evaluate Marketing Opportunities
- BSBWHS501 Ensure a safe workplace
- BSBWHS501 - Online Activities
- BSBWOR502 Lead and Manage Team Effectiveness
- COMP247 Data Communications
- ACC520 Legal Regulation of Business Structures Semester 2, 2019
- MKT01760 Tourism Planning Environments
- Science Literacy Assessment 4
- HPS771 - Research Methods in Psychology A
- HI5003 Economics for Business
- MNG03236 Report Writing
- TLIR5014 Manage Suppliers
- BFA301 Advanced Financial Accounting
- BSBWOR501 Assessment Task 3 Plan Personal Development Plan Project
- COMP10002 Foundations of Algorithms
- HI6028 Taxation Theory, Practice and Law T2 2019
- HI5020 Corporate Accounting T2 2019
- MKT01760 Tourism Planning Environments Assessment 4
- ACC508 Informatics and Financial Applications
- MA5830 Data Visualisation Assignment 2
- MRE5003 Industrial Techniques In Maintenance Management Assignment 4
- MRE5003 Industrial Techniques In Maintenance Management Assignment 3
- MRE5003 Industrial Techniques In Maintenance Management
- AERO2463 Computational Engineering Analysis Assignment 4
- SIT323 Practical Software Development Trimester 2, 2019
- TLIL5055 Manage a supply chain
- MKT01906 International Tourism Systems
- BSBHRM602 Manage Human Resources Strategic Planning
- CHCECE019 Early Childhood Education and Care
- BFA504 Accounting Systems Assessment 3
- MKT5000 Marketing Management S2 2019
- ACCT20074 Contemporary Accounting Theory Term 2 Assessment 3
- BSBFIM501 Manage Budgets And Financial Plans Assessment Task 1
- ELEC242 2019 Session 2
- BSBINM601 Manage Knowledge and Information
- HC2112 Service and Relationship Marketing Individual Assignment T2 2019
- FINM202 Financial Management Assessment 3 Group Report
- HC2121 Comparative Business Ethics & Social Responsibility T2 2019
- ITECH 5500 Professional Research and Communication
- MGT215 Project Management Individual Assignment
- ISYS326: Information Systems Security Assignment 2, Semester 2, 2019
- SITXCOM002 Show Social and Cultural Sensitivity
- ENN543, Data Analytics and Optimisation T2 2019
- BUSS1030 Accounting, Business and Society
- BSBADV602 Develop an Advertising Campaign
- BSBWHS521 Ensure a Safe Workplace For a Work Area
- NSB231 Integrated Nursing Practice Assignment Help
- CAB202 Microprocessors and Digital Systems Assignment Help
- CHCHCS001 Provide home and community support services
- HLTAAP001 Recognise healthy body systems
- HLTWHS002 Follow safe practices for direct client care
- COSC473 Introduction to Computer Systems
- HOTL5003 Hotel Property and Operations
- MITS5002 Software Engineering Methodology
- ITECH1103- Big Data and Analytics Assignment Semester 1, 2020
- ITECH1103- Big Data and Analytics – Lab 3 – Working with Data Items
- ITAP3010 Developing Data Access Solutions Project
- ISY2005 Case Study Assessment 2
- IFN619 Data Analytics for Strategic Decision Makers
- CHC40213 Certificate IV in Education Support
- SIT718 Using aggregation functions for data analysis
- Assignment 2 Introduction to Digital Forensics
- MGT603 Assessment 1
- MGT603 Assessment 2

## Follow Us