## [answered] MATH241 MATLAB Homework No submissions over mail, hardcopy

Hello. I have a matlab assignment due 12.12.2016. All details are in the attachment.

MATH241 MATLAB Homework

No submissions over mail, hardcopy only Q1.

In modeling the equilibrium temperature distribution in a metal rod, one may use the differential equation:

?2 ?? 2 ? ? ?=

?? ? , 0???1 where ? is the spatial location in the rod,? (? is an externally-applied heat source, and ? ? is the

)

temperature throughout the rod. A simple approximation

of this equation uses the formula

?2

?? 2 ? ? ? ? ?+? ?2? ? +? ???

?2 1 where ? = ??1. , Suppose the ends of the rod are held at a fixed temperature of 5, i.e. ? 0 = 5 and ? 1 = 5, and that

heat is applied evenly along the length of the rod, ? ? = 2.

If we store the solution values at ?locations in the rod, ?? = ? ? 1 ?, then these temperatures ?? ?

? ?? may be stored in a vector, ? = [?1, ?2, ? . ,???, and this vector solves a linear system of

equations ?? = ?,

1 = 5, ? ? 1

2

1

?1 + 2 ?2 ? 2 ?3 = 2

2

?

?

? ? 1

2

1

?2 + 2 ?3 ? 2 ?4 = 2

2

?

?

?

? ? 1

2

1

???2 + 2 ???1 ? 2 ?? = 2

2

?

?

?

? = 5. ? You may implement this in Matlab following few simple commands:

&gt;&gt;

&gt;&gt;

&gt;&gt;

&gt;&gt;

&gt;&gt;

&gt;&gt; N = 201;

h = 1/(N-1);

A = zeros(N,N);

A(1,1) = 1;

A(N,N) = 1;

for i=2:N-1

A(i,i-1) = -1/(h^2);

A(i,i) = 2/(h^2);

A(i,i+1) = -1/(h^2);

end

&gt;&gt; b = 2*ones(N,1);

&gt;&gt; b(1) = 5;

&gt;&gt; b(N) = 5; Perform the following tasks:

(a) Use the above commands to create the matrix A and right-hand side vector b.

(Do not print the matrix A and vector b in your report)

(b) Explore the function ? ? ? ( ) in MATLAB and use it to find the reduced row echelon form of

?

matrix ?.

(c) based on part b) show that the columns of matrix ? are linearly independent and hence the matrix

is invertible. Justify

(d) Without inverting ? find the reduced row echelon form of an augmented matrix [? ?]

(e) from d) find a unique solution to the problem ?u = ?

(f) Plot your result using the Matlab command plot(u)

(g) Check that Nul(A) contains only the zero vector by finding its basis with the command null(A). We now change the boundary conditions of the rod, so that instead of holding the temperature fixed, we

now insulate both ends from the environment; mathematically represented by ?

? 0 = 0,

?? ?

? 1 = 0

?? We may approximate these in our linear system by replacing our first and last equations with 2

2

?

?

? =2

1

?2

?2 2

? 2

2

?

+

? =2

??1

?2

?2 ? Perform the following tasks:

(h) Modify the first and last rows of your matrix? and right-hand side vector b to implement these

two equations.

(i) Try to solve for the temperature, by introducing new matrix ? =

[ ????([? ?]).Show that system of

linear equations ?? = ? becomes inconsistent. You may try as usual, ?\? in command window to

observe if the matrix is invertible or not.

(j) Determine a basis for Nul(A) for this new matrix ?.

(k) By looking at your basis from part (j), in a sentence or two, try to explain the physical meaning of

Nul(A) for this problem. Q2.

In the accompanying file, climate_data.txt, the average global temperature (in degrees Fahrenheit) is

provided for the years 1880 through 2015 [from NOAA.gov]. The first column of data contains the

number of years since 1880 (i.e. ?10? would be the year 1890), and the second column contains the

average global temperature for that year. As with any natural phenomena, these temperatures consist of

underlying trends overlaid with random fluctuations. We will use least-squares in an attempt to extract

these underlying trends.

Following MATLAB code constructs the best cubic polynomial fit to the data, use it to plot both the data

and resulting predictions from 1880 through 2025. The code is commented to better explain the process:

&gt;&gt; years = climate_data(:,1); % extract 1st column as &quot;years&quot; vector

&gt;&gt; temps = climate_data(:,2); % extract 2nd column as &quot;temps&quot; vector

% build the matrix and solve the least-squares system.

% Note: the .^ notation raises each entry to the requested power

&gt;&gt; A = [years.^3, years.^2, years.^1, years.^0]; % construct A

&gt;&gt; b = temps; % build the right-hand side

&gt;&gt; x = (A'*A) \ (A'*b); % solve the least-squares problem

% set the dates that we want to plot over (offset by 1880)

&gt;&gt; dates = linspace(0,145,200);

% compute the projections based on the model

&gt;&gt; proj = x(1)*dates.^3 + x(2)*dates.^2 + x(3)*dates.^1 + x(4)*dates.^0;

% plot the data as black dots and the model as a blue line

&gt;&gt; plot(years+1880,temps,'k.',dates+1880,proj,'b-')

&gt;&gt; xlabel('year')

&gt;&gt; ylabel('temperature')

&gt;&gt; title('Climate data and cubic fit') Note here that our cubic polynomial has the form

?(? ) = 1?3 + ?2?2 + 3?? + 4?

?

so the matrix in our over determined linear system has the form ?= 3

?

?12 ?1

1

?

?23 ?22 ?2

? ? ?

3

??

??2 ?? 1

1=

?

1 ?13 ?12 ?11 ?10

?23 ?22 ?21 ?20

? ? ? ?

??3 ??2 ??1 ??0 Since years is a column vector with the values [?1 ?2 . . ?.? ]? , this is why we can construct the full matrix

? in Matlab with the one line command A = [years.^3, years.^2, years.^1, years.^0] Perform the above commands. Repeat the process for both a quadratic model and a linear model.

For these models, you should only need to modify the lines

A = [years.^3, years.^2, years.^1, years.^0]; and

proj = x(1)*dates.^3 + x(2)*dates.^2 + x(3)*dates.^1 + x(4)*dates.^0; and

title('Climate data and cubic fit') Turn in printouts of your three plots for question 2 only. DO NOT print matrices A and b for either questions 1 and 2!!

Solution details:
STATUS
QUALITY
Approved

This question was answered on: Sep 18, 2020

Solution~0001013688.zip (25.37 KB)

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy from our tutoring website www.aceyourhomework.com (Deadline assured. Flexible pricing. TurnItIn Report provided)

STATUS

QUALITY

Approved

Sep 18, 2020

EXPERT

Tutor