联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Matlab编程Matlab编程

日期:2019-03-02 09:56

Computational Project 3

due: 03/04/2019, 5 p.m.

Last updated February 27, 2019.

Instructions

New format guideline! Submit electronic copy of code, which must produce and

display all requested figures and output, and also submit a hard copy only of answers

to questions not already included directly in your code output. Results output to the

screen must use fprintf and an indicator of which question is being answered, for

example,

fprintf(‘Prob 1(b): best estimate of viscosity is %f \n’, viscosity)

Data files such as stress.txt and the LagrangeINT.m will be located in the TAs’ local

directory when they test your code, so you don’t need to include these in your code.

Problems

1. Consider a fluid with velocity vx in the x-direction changing as a function of y.

The sheer stress in a fluid, τ , is related to the viscosity μ and the strain rate, γ,

where γ =vxy . For pseudo plastic fluids, e.g., shampoo, these are related as

τ = μγn

For Newtonian fluids, these are related asτ = μγ

For Bingham plastics (e.g., toothpaste), there is a threshold, τy, to overcome before

Newtonian fluid properties are exhibited. In this case the stress-strain relationship isτ = τy + μγ

You have performed experiments at a variety of strains and measured the resulting

stresses on an unclassified fluid sample. The data are in the strain.txt and

stress.txt files. Using this data set, write code that uses linear regression to fit the

data for each of the three potential models described above. You may solve the regression

equations yourself or use MATLAB statistical commands, such as regstats.

For each of the three models, your code should generate a scatter plot of the stress

versus strain data along with the regression line. In a separate plot, also show the

1

residuals (ri

’s) as a function of the strain rates for each fit. Use the subplot command

to put all of these plots into a single figure. Clearly label your plots (titles,

axis labels, legends).

Based on further analysis of your results, include a writeup that answers the following

questions:

(a) to which class of fluids does this sample most likely belong? Justify your answer.

(b) what is your best estimate of the sample’s viscosity?

2

2. In this problem we will explore the fitting of data points yi with polynomial functions

of order p at various values of xi

, where

yi = a0 + a1xi + a2x2i + a3x3i + . . . + apxpi + ri,

and ri is the residual error. This relationship can be summarized more concisely as

y = Xa + r. The following steps explore how different approaches to finding the

coefficients a lead to better or worse fits to the data.

(a) Download data for x (temperature.txt) and y (density.txt) for a liquid metal.

Plot the density [g/cm3

] as a function of temperature [K].

(b) Calculate the coefficients of a 5th order regression polynomial using the polyfit

function. Then, using polyval, evaluate this polynomial as x goes from 396 to

512 in intervals of size 0.5. Add a plot of this polynomial to your figure as a

solid black line.

(c) Calculate the coefficients of a 5th order regression polynomial by directly solving

a = (XT X)1XT y.

Then, using polyval, evaluate this polynomial as x goes from 396 to 512 in

intervals of size 0.5. Add a plot of this polynomial to your figure as a solid blue

line. For a calculated this way, you may need to flip a in order to use polyval.

(d) Repeat (b), but for p=24. Add a plot of this polynomial to your figure as a

dashed black line.

(e) Repeat (c), but for p=24. Add a plot of this polynomial to your figure as a dashed blue line.

(f) Use the LagrangeINT.m function that comes with your textbook to evaluate a

24th order interpolating polynomial as x goes from 396 to 512 in intervals of

size 0.5. Add this polynomial to your plot as a solid green line.

(g) Add a legend to your plot, labeling all lines. Use the axis command to restrict

the y-axis range of your plot so that the different lines and datasets are clearly

discernible.

(h) Which numerical method of finding the regression polynomial works better for

small values of p? For large values of p?

(i) Using the best polynomial you found, estimate the metal’s density at 440 K.

(j) BONUS: For polynomial fits of order p = 2 to p = 24, calculate the sum of

squared residual error (E =Pni=1 r2i) using both the method in part (b) and

part (c). Plot E for each as a function of p on the same plot. The range of

values of E spans several orders of magnitude, so use a logscale for the y-axis

with the semilogy command.

3

Table 1:

x y

0 0

1 -6.6

2 9.1

3 6.4

4 -7.6

3. Given the following data,

calculate the equations for an ‘unnatural’ quadratic spline. This type of spline imposes

as an additional constraint that the second derivative of the spline is zero for

the last spline (between x = 3 and x = 4), instead of for the first spline.

(a) Write down the set of equations you need to solve to find all of the spline

coefficients.

(b) Find the polynomial coefficients of each spline function.

(c) Plot the data and the interpolating spline functions between the data points.

Tip: here is some code to plot a quadratic polynomial with coefficients a(1),

a(2), and a(3) over the range from x(1) to x(2),

syms xs

f = a(1) + a(2) * xs + a(3) * xs^2

ezplot(f,[x(1) x(2)])

(d) Add to your plot a cubic spline calculated using MATLAB’s spline command.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp