当前位置:文档之家› 华南理工大学《计算方法》实验报告

华南理工大学《计算方法》实验报告

华南理工大学《计算方法》实验报告华南理工大学《计算方法》实验报告学院计算机科学与工程专业计算机科学与技术(全英创新班)学生姓名 -------学生学号 ------------指导教师布社辉课程编号 145022课程学分 3 分起始日期 2015年5月28日实验题目一Solution of Nonlinear Equations--Bracketing method and Newton-Raphson method姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】1.Find an approximation (accurate to 10 decimal places) for the interest rate I thatwill yield a total annuity value of $500,000 if 240 monthly payments of $300 are made.2.Consider a spherical ball of radius r = 15 cm that is constructed from a variety ofwhite oak that has a density of ρ = 0.710. How much of the ball (accurate to eight decimal places) will be submerged when it is placed in water?3.To approximate the fixed points (if any) of each function. Answers should beaccurate to 12 decimal places. Produce a graph of each function and the line y = x that clearly shows any fixed points.(a) g(x) = x5 − 3x3 − 2x2 + 2(b) g(x) = cos(sin(x))【实验分析】1.Assume that the value of the k-th month is , the value next month is, whereSo the total annuity value after 240 months is :To find the rate I that satisfied A=5000000, we can find the solution to the equationThe Bisection method can be used to find the solution of .2.The mass of water displaced when a sphere is submerged to a depth d is:The mass of the ball isAppl ying Archimedes’ law, , produce the following equations:So g(d)=, and Bisection method can be used to find the root.3.In this problem, the target is to find the fixed point by fixed point iteration. So wecan use fixed point iteration method to solve the problem.(a),so ,Plot the function g(x) and y=x, it can be seen that there are three fixed point, where ,It can be solved that:for,for,for,So, ,,, they are all repelling fixed point, fixed point iteration method cannot converge to them.(b). From the graph below we know that the fixed point liesbetween 0.5 and 1. Where . So the fixed point is attractive fixed point. I initially guess that p=0.75, and apply fixed point iteration method to find the solution.【实验过程和程序】1.The value of g(I) will change significantly but little change of I, so that it’sunwise to plot the figure about I and g(I). Instead, the interest will be bound by [0,1] by common sense. So I set the left end point of Bisection method to 0, right end point to 1. The precision is set to 1e-10.Code for g(I) is :Code for applying Bisection method is :2.The since the density of the ball is smaller than water, so depth submerged shouldnot be larger than 2r, and not less than 0. So I set the left end point of Bisection method to 0 and right to 2r.Code for g(d) is :Code for applying Bisection method is :3.(a)Code for function g:Code for applying fixed point iteration:Code for plot the graph:(b)Code of this problem is similar to the previous one, so it’s not illustrated here.【实验结果】1.Result for the program is :So the annual interest rate is 31.78710938%2.X-axis is the depth and Y-axis is for g(d). Blue line is the function value versusdepth. Red line is y=0. It can be seen from the graph that the solution is about 19.And by using Bisection method, the solution depth=19.306641cm is found, with8 significance bit.3.(a) No fixed point can be found. By solving this equation, we can find that x=2 isone of the solution. If we set the initial point to 2.00000000001 or 1.9999999, the result is the same:. If we set initial point to 2, the point can be found:. This is consistent with the conclusion discussed in the previous part.(b)The fixed point p=0.768169156736 is found:实验题目二Solution of Linear Systems--Gaussian elimination and pivoting姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】Find the sixth-degree polynomial y = a1 + a2x + a3x^2 + a4x^3 + a5x^4 + a6x^5 + a7x^6 that passes through (0, 1), (1, 3), (2, 2), (3, 1), (4, 3), (5, 2), and (6, 1). Use the plot command to plot the polynomial and the given points on the same graph. Explain any discrepancies in your graph.【实验分析】To find the coefficient of each term, we can substitute all the given point to the equations and construct an argument matrix AX=B. Then perform triangular factorization and solve the upper-triangular and lower triangular matrix by back substitution method.Since det(A) = 2.4883e+07 ≠ 0,there exist a unique solution for AX=B.【实验过程和程序】Code for construct coefficient matrix A:Code for construct matrix B:Solve X by triangular factorization and back substitution method:【实验结果】The result for coefficient matrix:The graph of the polynomial is shown below. Blue lines denotes the graph for the polynomial and red points are the sample points. This polynomial fits the points well.Iterat ion of Linear System’s solution--Seidel iteration姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】(a)Start with P0 = 0 and use Jacobi iteration to find Pk for k = 1, 2, 3. Will Jacobi iteration converge to the solution?(b) Start with P0 = 0 and use Gauss-Seidel iteration to find Pk for k = 1, 2, 3. Will Gauss-Seidel iteration converge to the solution?【实验分析】In this problem we only need to construct the coefficient matrix and matrix B and then apply the Jacobi Iteration method and Gauss-Seidel Iteration method to find the solution. SinceA satisfy strictly diagonally dominant, so the iteration steps will converge.【实验过程和程序】【实验结果】Points in first three iteration is shown below. Both this two method will converge.Interpolation--Spline interpolation姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】The measured temperatures during a 5-hour period in a suburb of Los Angeles on November 8 are given in the following table.(a)To construct a Lagrange interpolatory polynomial for the data in the table.(b)To estimate the average temperature during the given5-hour period.(c)Graph the data in the table and the polynomial frompart (a) on the same coordinate system. Discuss thepossible error that can result from using thepolynomial in part (a) to estimate the averagetemperature.【实验分析】(a)X=[1,2,3,4,5,6] Y=[66,66,65,64,63,63], the target is to construct a Lagrangeinterpolatory polynomial for X and Y. We can apply the Lagrange approximation method to solve it.(b)After we get the interpolatory polynomial, we can use a great amount of samplepoints and estimate the function value of them and take the mean.(c)Error contain in Lagrange interpolatory polynomial of 5-degree is:, where Error on the average temperature equals to the mean of , which is:Error ====240.06【实验过程和程序】(a)Construct X and Y, and solve it by Lagrange approximation:(b)After we get the polynomial function, we calculate function value on a set ofsample points and get their mean as the average temperature.(c)plot X_new and Y_new in part(b) is equivalent to plot P N(x). And error bound canonly be obtain by analyzing since f(x) is unknown.【实验结果】(a) We can get the result:Which means that:(b)By taking the mean, the average temperature is 64.5℉:(c)The graph for polynomial and the sample points is shown below. Error bound forthe average temperature is 240.06.实验题目五Curve Fitting--Least mean square error姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】1.The temperature cycle in a suburb of Los Angeles on November 8 is given in theaccompanying table. There are 24 data points.(a)Follow the procedure outlined in Example5.5 (use the fmins command) to find theleast-squares curve of the form f (x) = Acos(Bx)+C sin(Dx)+ E for the given set ofdata.(b)Determine E2( f ).(c)Plot the data and the least-squares curvefrom part (a) on the same coordinatesystem.【实验分析】(a)In this problem. The hour 1~midnight p.m. can be map to 1~12, 1~noon a.m. canbe map to 13~24. So hour and temperature can be used to fit the curve. To get the curve with minimum error, which is define as:The best A, B, C, D, E can be found when:(b)is defined as:In our case,【实验过程和程序】(a) The function of the error is:Using command, A B C D E can be solved. (b) By the function solved by part(a), we can calculate for each sample pointand then calculate :(c) Code to plot the line:【实验结果】(a)The result for parameter A B C D E is:So the least-squares curve is :(b)Error for f(x) is:(c)Graph for least-squares curve and sample points is:Notice that the result of function fminesarch is sensitive about the input seeds.Firstly the seed is [1 1 1 1 1], and get the result [0.1055 -2.1100 0.9490 -4.869861.0712]. In second step, seed is [0.1 2 1 -5 61] and result is [0.0932 2.11141.175 -5.127 61.0424]. By 4 iterations, I find a good fit of the data and get the seed[1 0.1 1 1 60].Numerical Integration--Automatically select the integration step of the trapezoidal method姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】(i) Approximate each integral using the compositetrapezoidal rule with M = 10.(ii) Approximate each integral using the compositeSimpson rule with M = 5.【实验分析】The formula of each function is given in this problem, so we just need to use composite trapezoidal rule and composite Simpson rule to solve them.【实验过程和程序】Function of the six equations:Code for calculation:【实验结果】Solution of Differential Equations--Euler’s Method and Heun’s Method姓名:xxxxxx学号:xxxxxxxxxxxx时间:2015年5月28日【题目】(Supplement) A skydiver jumps from a plane, and up to the moment he opens theparachute the air resistance is proportional to (v represents velocity). Assume that the time interval is [0,6] and hat the differential equation for the downward direction isover [0,6] with v(0)=0Use Euler’s method with h=0.05 and estimate v(6).【实验分析】The function of , where left end point is 0 and right is 6, with initial point v(0)=0. So we can apply Euler’s method directory to solve the problem.【实验过程和程序】Function of :Code of applying Euler’s method:【实验结果】….,so v(6)=10.0726.。

相关主题