Skip to content

Files

Latest commit

 

History

History
88 lines (56 loc) · 3.23 KB

README.md

File metadata and controls

88 lines (56 loc) · 3.23 KB

Homework #6

due 4/14 by 11:59pm

  1. Create a new github repository called 'curve_fitting'.

    a. Add rcc02007 and pez16103 as collaborators.

    b. Clone the repository to your computer.

  2. Create a least-squares function called least_squares.m that accepts a Z-matrix and dependent variable y as input and returns the vector of best-fit constants, a, the best-fit function evaluated at each point f ( x i ) , and the coefficient of determination, r2.

[a,fx,r2]=least_squares(Z,y);

Test your function on the sets of data in script problem_1_data.m and show that the following functions are the best fit lines:

a. y=0.3745+0.98644x+0.84564/x

b. y=-11.4887+7.143817x-1.04121 x^2+0.046676 x^3

c. y=4.0046e^(-1.5x)+2.9213e^(-0.3x)+1.5647e^(-0.05x)
  1. Use the Temperature and failure data from the Challenger O-rings in lecture_18 (challenger_oring.csv). Your independent variable is temerature and your dependent variable is failure (1=fail, 0=pass). Create a function called cost_logistic.m that takes the vector a, and independent variable x and dependent variable y. Use the function, σ ( t ) = 1 1 + e t where t = a 0 + a 1 x . Use the cost function,

    J ( a 0 , a 1 ) = 1 / m i = 1 n [ y i log ( σ ( t i ) ) ( 1 y i ) log ( ( 1 σ ( t i ) ) ) ]

    and gradient

    J a i = 1 / m k = 1 N ( σ ( t k ) y k ) x k i

    where $x_{k}^{i} is the k-th value of temperature raised to the i-th power (0, and 1)

    a. edit cost_logistic.m so that the output is [J,grad] or [cost, gradient]

    b. use the following code to solve for a0 and a1

% Set options for fminunc
options = optimset('GradObj', 'on', 'MaxIter', 400);
% Run fminunc to obtain the optimal theta
% This function will return theta and the cost
[theta, cost] = ...
fminunc(@(a)(costFunction(a, x, y)), initial_a, options);

c. plot the data and the best-fit logistic regression model

plot(x,y, x, sigma(a(1)+a(2)*x))
  1. The vertical stress under a corner of a rectangular area subjected to a uniform load of intensity q is given by the solution of the Boussinesq's equation:

    σ z = q 4 π ( 2 m n m 2 + n 2 + 1 m 2 + n 2 + 1 + m 2 n 2 m 2 + n 2 + 2 m 2 + n 2 + 1 + s i n 1 ( 2 m n m 2 + n 2 + 1 m 2 + n 2 + 1 + m 2 n 2 ) )

    Typically, this equation is solved as a table of values where:

    σ z = q f ( m , n )

    where f ( m , n ) is the influence value, q is the uniform load, m=a/z, n=b/z, a and b are width and length of the rectangular area and z is the depth below the area.

    a. Finish the function boussinesq_lookup.m so that when you enter a force, q, dimensions of rectangular area a, b, and depth, z, it uses a third-order polynomial interpolation of the four closest values of m to determine the stress in the vertical direction, sigma_z=$\sigma_{z}$. Use a 0 t h -order, polynomial interpolation for the value of n (i.e. round to the closest value of n).

    b. Copy the boussinesq_lookup.m to a file called boussinesq_spline.m and use a cubic spline to interpolate in two dimensions, both m and n, that returns sigma_z.