Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

answer in matlab please lD0 pts Th class+30 pts online) 4. (50 points) This ques

ID: 3720517 • Letter: A

Question

answer in matlab please

lD0 pts Th class+30 pts online) 4. (50 points) This question will test your ability to convert an algorithm into code. Below is the algorithm for creating the matrices used in Newtonian Formulation. This algorithm will work for any number of data points. Write a script based on the below algorithm and test it with C as your independent variable and D as your dependent variable from FinalExamQ4.mat. Background: Recall that the coefficient matrix for 2d order Newtonian formulation looks like this: 0 0 1 (x2 x1) (x3 ) (x3 x(x3-x2) There are 3 different areas in this matrix: 1) 2) 3) The upper portion is all zeros The first column is all ones The bottom portion involves the data points, additionally, each column is a multiple of the column before it. For instance, looking at the bottom row: the second column is the first column times (k-xa) and the third column is the second column times (xox). Remember t pattern will continue if a larger order equation is required (i.e. if you have more data points) Algorithm 1) Get the data into two vectors 2) Determine how many numbers are in those vectors 3) Initialize the square matrix of all zeros, this will cover item 1 above 4) Use loops to step through the matrix one item at a time. You need to work through an entire COLUMN before moving on to the next one. Each value in the matrix is dependent on its position as follows: 5) When the column is larger than the row the value says 0 When the column is 1 the values is 1 Everything else the value will be the value in the previous column times the independent variable that corresponds to that row minus the independent variable that corresponds to one less than the column. For example, the value in row 3, column 2 will be equal to the value in row 3, column 1 times the third independent variable minus the first independent variable. a. b. c. 6) The dependent variables need to be in a vertical vector 7) Use the backslash to solve the system of equations you created 8) Show the matrix you created, the dependent variable vector, and the results of part 7 in th command window.

Explanation / Answer

x=input('Enter vector x(independent variable): '); y=input('Enter vector y(dependent variable): '); n=length(x); comat=zeros(n,n); for i=1:n for j=1:n if i==1 comat(j,i)=1; elseif i