MATLAB Function - Homework 3 | Computational Mathematics | MA 402, Assignments of Mathematics

Material Type: Assignment; Professor: White; Class: Computational Mathematics: Models, Methods and Analysis; Subject: Mathematics; University: North Carolina State University; Term: Fall 2004;

Typology: Assignments

Pre 2010

Uploaded on 03/11/2009

koofers-user-6wc
koofers-user-6wc 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MA402, Homework #3
Due Thursday, October 4, 2001
1. Consider the following Matlab function
function [y1,y1,y3,y4,y5] = my_test(x,n)
y1 = 1; y2=1; y3=1; y4=1; y5=1;
for i=1:n
y1 = y1*i; y2=y2*(-x); y3=y3*y3;
y4 = y4 + y2/y1;
y5 = y5 + y3/y1;
end
Answer the following question:
(a) What are the inputs and outputs of the Matlab function?
(b) Write down the equivalent mathematical expressions for all the outputs?
(c) Verify your expression for x= 2 and n= 5 by running the code and checking with
your mathematical expressions, see use a calculator.
2. Evaluate the 1-norm, 2-norm, and the infinity norm for the following vectors and matrices
(pay attention to absolute values).
(a) x=(3,4,0,3/2)T.
(b) x=(sink, cos k, 2k)Tfor a fixed positive integer k.
(c) A=
8112
2811
0311
6011
. Evaluate kAk1,andkAkonly.
3. Study the diffusion-reaction model given by
ut=f+βuxx auxcu, 0<x<1,
u(x, 0) = sin(πx),initial condition,
u(0,t)=0,u(1,t)=0,boundary condition,
f(x, t)=et¡sin(πx)+ cos(πx)+csin(πx)+βπ2sin(πx)¢.
(a) Show that u(x, t)=etsin(πx) is a solution. That is: (1) it satisfies the differential
equation (verify the left hand side equals the right hand side); (2) it satisfies the initial
condition; (3) it satisfies the boundary condition.
pf2

Partial preview of the text

Download MATLAB Function - Homework 3 | Computational Mathematics | MA 402 and more Assignments Mathematics in PDF only on Docsity!

MA402, Homework # Due Thursday, October 4, 2001

  1. Consider the following Matlab function

function [y1,y1,y3,y4,y5] = my_test(x,n) y1 = 1; y2=1; y3=1; y4=1; y5=1; for i=1:n y1 = y1i; y2=y2(-x); y3=y3*y3; y4 = y4 + y2/y1; y5 = y5 + y3/y1; end

Answer the following question:

(a) What are the inputs and outputs of the Matlab function? (b) Write down the equivalent mathematical expressions for all the outputs? (c) Verify your expression for x = 2 and n = 5 by running the code and checking with your mathematical expressions, see use a calculator.

  1. Evaluate the 1-norm, 2-norm, and the infinity norm for the following vectors and matrices (pay attention to absolute values).

(a) x = (3, − 4 , 0 , 3 /2)T^. (b) x = (sin k, cos k, 2 k)T^ for a fixed positive integer k.

(c) A =

. Evaluate ‖A‖ 1 , and ‖A‖∞ only.

  1. Study the diffusion-reaction model given by

ut = f + βuxx − aux − cu, 0 < x < 1 , u(x, 0) = sin(πx), initial condition, u(0, t) = 0 , u(1, t) = 0, boundary condition, f (x, t) = e−t^

− sin(πx) + aπ cos(πx) + c sin(πx) + βπ^2 sin(πx)

(a) Show that u(x, t) = e−t^ sin(πx) is a solution. That is: (1) it satisfies the differential equation (verify the left hand side equals the right hand side); (2) it satisfies the initial condition; (3) it satisfies the boundary condition.

(b) Formulate a finite difference scheme to solve the problem (use the central finite differ- ence for spatial variable, and forward finite difference for time variable). (c) Write down the matrix-vector form (uk+1^ = Auk^ +bk) of your finite difference equation. (d) Is there a steady state solution? If so, write down the differential equation for the steady state solution, and the linear system of equations of for the discrete steady state solution of the form Bu∗^ = b. (e) Test and debug your code (you can start with heatc.m) with β = 1, a = 1, and c = 1, tf inal = 1, and ∆t = h^2 /(2. 5 β). Compare with you results with the exact solution using 2-norm and fill-in the following table.

m error ‖em‖ 2 ratio (‖em‖ 2 /‖e 2 m‖ 2 ) 10 N/A 20 40 80 160

Table 1: Grid refinement analysis of the finite difference method. The order of convergence is about 2 meaning ‖e‖ 2 = O(h^2 ) since the ratio approach to 4.

Plot the solution for m = 80.

(f) Now fix β = 1, c = 1, tf inal = 1, and m = 50. Run you code with a = 10, a = 100, a = 1000, a = 10000, a = 100000. Did you observe anything? (g) Extra credit: Can you propose a different finite difference that may work better when a is large?