#!/usr/bin/env python # coding: utf-8 # Engy-5310: Computational Continuum Transport Phenomena Fall 2021 UMass Lowell; Prof. V. F. de Almeida **05Oct21** # # # Homework 03 (05Oct21) # # $ # \newcommand{\Amtrx}{\boldsymbol{\mathsf{A}}} # \newcommand{\Bmtrx}{\boldsymbol{\mathsf{B}}} # \newcommand{\Mmtrx}{\boldsymbol{\mathsf{M}}} # \newcommand{\Imtrx}{\boldsymbol{\mathsf{I}}} # \newcommand{\Pmtrx}{\boldsymbol{\mathsf{P}}} # \newcommand{\Lmtrx}{\boldsymbol{\mathsf{L}}} # \newcommand{\Umtrx}{\boldsymbol{\mathsf{U}}} # \newcommand{\Smtrx}{\boldsymbol{\mathsf{S}}} # \newcommand{\xvec}{\boldsymbol{\mathsf{x}}} # \newcommand{\avec}{\boldsymbol{\mathsf{a}}} # \newcommand{\bvec}{\boldsymbol{\mathsf{b}}} # \newcommand{\cvec}{\boldsymbol{\mathsf{c}}} # \newcommand{\rvec}{\boldsymbol{\mathsf{r}}} # \newcommand{\fvec}{\boldsymbol{\mathsf{f}}} # \newcommand{\mvec}{\boldsymbol{\mathsf{m}}} # \newcommand{\gvec}{\boldsymbol{\mathsf{g}}} # \newcommand{\zerovec}{\boldsymbol{\mathsf{0}}} # \newcommand{\norm}[1]{\bigl\lVert{#1}\bigr\rVert} # \newcommand{\transpose}[1]{{#1}^\top} # \DeclareMathOperator{\rank}{rank} # \newcommand{\Reals}{\mathbb{R}} # \newcommand{\thetavec}{\boldsymbol{\theta}} # $ # ### Name: `your name` # ### Rubric for each assignment: # # | Context | Points | # | ----------------------- | ------- | # | Precision of the answer | 80% | # | Answer Markdown readability | 10% | # | Code readability | 10% | # ### Guidance: # # + # Save your work frequently to a file locally to your computer. # # + # During your work and before submitting the final version do: Kernel -> Restart & Run All, to verify your notebook runs correctly. # # + # Save your file again. # # + # Upload the notebook file in the Blackboard submission portal as: # # # **lastname-firstname-labwork-xx.ipynb** # --- # ## Table of Assignments # * [Assignment 1 (30 pts)](#a1) Function approximation with constrained end-points. # - [1.1)](#a11)(5 pts) Generate the target function. # - [1.2)](#a12)(10 pts) Compute parameters for a given error level. # - [1.3)](#a13)(15 pts) Using the same basis functions, approximate the target function continuously ($m\rightarrow\infty$) and constrain the end points. # * [Assignment 2 (65 pts)](#a2) Function approximation with constrained end-point derivatives. # - [2.1)](#a21)(35 pts) Constrained Fourier basis function approximation. # - [2.2)](#a22)(30 pts) Demonstrate why the approximation results for the end point derivatives can't be improved. # * [Assignment 3 (5 pts)](#a3) . # --- # ## [Assignment 1 (30 pts)](#toa) # ### [1.1)](#toa)(5 pts) Generate the following piecewise linear function on these shape points: #
# # $\{(-8,1),(-6,10),(-5,-7),(0,-5),(1,9),(2,-8),(3,28),(5,-23),(7,12),(9,1),(10,10),(12,15),(14,18),(15,10)\}$. # # In[2]: '''Generate the target function f''' # ### [1.2)](#toa)(10 pts) Compute "the best" approximant function $g$ using Wavelet basis functions with adequate parameters to approximate $f$ with a relative $L_2$ norm below 30% error; use a continuous approximation equivalent to an infinite number of collocation points ($m\rightarrow\infty$). Report the number of packets, modes, and other parameters used, show a comparison plot, compute the $L_2$ norm relative error. Explain why the end points of the approximation do not match the given data. # # In[3]: '''Build the basis functions''' # In[9]: '''Plot comparison of f and g_best_vec''' # In[10]: '''L2 norm error''' # **Explanation:** # ### [1.3)](#toa)(15 pts) Constrain the end points of the approximation in 1.2) and compute the relative error. Show in a plot a comparison of the constrained and unconstrained results. Explain the method to constrain the end points and whether the method was effective in this case. # # In[15]: '''Plot comparison of f and g_best_vec with constrained end points''' # In[16]: '''L2 norm error''' # In[17]: '''Code for comparison of methods''' # **Explanation:** # ## [Assignment 2 (65 pts)](#toa) # ### [2.1)](#toa)(35 pts) Approximate the piecewise linear function of 1.1) using Fourier Basis functions using 8 modes so that both the end points and the derivative at the end points are constrained by the corresponding values of the target function. Compute the relative error. Explain the method you developed and your results. # In[18]: '''Build the basis functions list''' # In[24]: '''Plot comparison of f and g_best_vec with constrained values and derivative at end points''' # In[25]: '''L2 norm error''' # **Explanation:** # ### [2.2)](#toa)(30 pts) Show numerically why the derivative at the end points cannot match the target function derivatives. Explain. # **Explanation:** # ## [Assignment 3 (5 pts)](#toa) # ### Describe the most unclear point in the content presented so far. Then, make an effort to clarify the point on your own. # **Answer:** # In[ ]: