Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

2022 Gen 12 Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

University of Science and Technology of Hanoi Intake: Academic year: 2022-2023

Subject: Numerical Methods Date: Time: 60 mins


Important instructions
Final Examination: Matlab/Octave 1. Discussions are strictly prohibited
N0: 01 2. Communication devices are not allowed
Instruction:
- Use help in Matlab/Octave
̅̅̅̅̅̅ is the last 3 digits of your student ID (e.g: BI12-050 → 𝐴𝐴𝐴
- In Question 1a, 2b and 3c, 𝐴𝐴𝐴 ̅̅̅̅̅̅ = 50)
̅ is the last digit of your student ID (e.g: BI12-050 → 𝑀
- In Question 1b and 2c, 𝑀 ̅ = 0)

Question 1: (6pts)
a. Calculate the arithmetic operations below:
i. 123 + 15! – √𝐴𝐴𝐴
̅̅̅̅̅̅
ii. Define a column vector x = (1, 2, 3, 4, 5); Transpose this vector?

b. Calculate the matrix:


i. Sum of A and B
A = [1 2 3 B = [1 1 𝑀̅
4 5 6 0 1 0
7 8 9] 0 0 1]
ii. Calculate C = A*B and D = A.*B. Explain the difference between the two (using
comment).
iii. Find the eigenvalues of matrix D.
iv. Find the matrix E which is the inverse of the matrix (A-B).
v. Reduce the size of E to 2x2 by removing row 2 and column 2 of the original matrix
using operator ‘:’.

̅ . Compute y for x = 0, 1, 2,…, 30 and


c. Given the line-equation on 2-D plane: y = 2x + 𝑀
plot those (x,y) points on 2-D plane by command “plot()”. Give appropriate title, axis
labels and legend for the plot.

Question 2: (8pts)
a) Determine an equation using curve fitting in Matlab to predict the metabolism rate as a
function of mass based on the following data. Use it to predict the metabolism rate of a
200-kg tiger:

b) Use the function newtraph.m to find the root of the function 𝑦 = 𝑥 2 − ̅̅̅̅̅̅
𝐴𝐴𝐴 (select
suitable guess, tolerance, number of iterations).
function [root,ea,iter]=newtraph(func,dfunc,xr,es,maxit)
% newtraph: Newton-Raphson root location zeroes
[root,ea,iter]=newtraph(func,dfunc,xr,es,maxit,p1,p2,...):
% uses Newton-Raphson method to find the root of func
% input:
% func = name of function
% dfunc = name of derivative of function
% xr = initial guess
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by function
% output:
% root = real root
% ea = approximate relative error (%)
% iter = number of iterations
iter = 0;
while(1)
xrold = xr;
xr = xr - func(xr)/dfunc(xr);
iter = iter + 1;
if xr ~= 0, ea = abs((xr - xrold)/xr) * 100; end
if ea <= es | iter >= maxit, break, end
end
root = xr;

1 1 1 1 1
c) Write a script file to computes and display 1      ...  using for statement
3 5 7 9 1003
d) Solve the system of linear equation using three methods: inv, mldivide, and lu:
𝑥 − 2𝑦 + 3𝑧 = 9
−𝑥 + 3𝑦 − 𝑧 = −6
2𝑥 − 5𝑦 + 5𝑧 = 17

Question 3: (6pts)
a. A company makes two types of products A and B. These products are produced during a
40-hour work week and then shipped out at the end of the week. They require 20 and 5 kg
of raw material per kg of product, respectively, and the company has access to 9500 kg of
raw material per week. Only one product can be created at a time with production times
for each of 0.04 and 0.12 hr, respectively. The plant can only store 550 kg of total product
per week. Finally, the company makes profits of $45 and $20 on each unit of A and B,
respectively. Each unit of product is equivalent to a kg.
Solve the problem above to maximize profit using function linprog ?

b. Given the function: (𝑥) = 2 + 𝑥 3 + 𝑒 2𝑥+1 . Use the forward difference formula to
differentiate the function f(x) with the step 0.1 and 0.01.

c. Calculate the integral of f(x) from 0 to 0.8: 𝑓(𝑥) = ̅̅̅̅̅̅


𝐴𝐴𝐴 + 25𝑥 − 𝑥 2
i. Use trapz function.
ii. Use quad function.

———————–∗ ∗ ∗ The end ∗ ∗ ∗———————–

You might also like