Question: MATLAB Here's the solve.m: %% % Solve for the linear system Ax = b % % The parameters received are: % - A (m x


MATLAB
Here's the solve.m:
%% % Solve for the linear system Ax = b % % The parameters received are: % - A (m x n): a rectangular matrix % - b (m x 1): right hand side of a linear system % % The function should return % - x (n x 1): solution vector [x_1, x_2, ..., x_n]
function x = solve(A, b) augmented_matrix = [A b]; % you can change it to rref if your my_rref does not work R = rref(augmented_matrix); x = R(:, end); end
Here's gps2d.m hint:
%% % Solve for the 2D coordinate of P as a problem of linear system % % The parameters received are: % - a (2 x 1): 2D coordinate of point A % - b (2 x 1): 2D coordinate of point B % - c (2 x 1): 2D coordinate of point C % - ra (1 x 1): distance from A to P % - rb (1 x 1): distance from B to P % - rc (1 x 1): distance from C to P % % The function should return % - p (2 x 1): 2D coordinate of P
function p = gps2d(a, b, c, ra, rb, rc) %%%% YOUR CODE STARTS HERE
end
Here's gps3d.m hint
%% % Solve for the 3D coordinate of P as a problem of linear system % % The parameters received are: % - a (3 x 1): 3D coordinate of point A % - b (3 x 1): 3D coordinate of point B % - c (3 x 1): 3D coordinate of point C % - d (3 x 1): 3D coordinate of point D % - ra (1 x 1): distance from A to P % - rb (1 x 1): distance from B to P % - rc (1 x 1): distance from C to P % - rd (1 x 1): distance from D to P % % The function should return % - p (3 x 1): 3D coordinate of P
function p = gps3d(a, b, c, d, ra, rb, rc, rd) %%%% YOUR CODE STARTS HERE
end
4 GPS localization (30 points) One real-life application of solving linear systems is GPS localization. For simplicity, let us work in a 2D world first. Suppose your cellphone receives signals from three GPS satellites at known positions A= (Q1, Q2), B = (b, b), and C = (c.cz), and can measure its distances TA,TB, rc from all of them, as shown below. C=(4,4)=(-11,6 =13 A=14,4)=(45) B=(5,6)=(5-2) This gives us three quadratic equations for our own position P = (x,y): =(1-1) + (Q2 - y)? = (6. - 1)2 +62-y), =( -1)+(2-y). Subtracting equation (la) from equation (lb) and equation (1b) from equa- tion (le), then simplifying, gives us a 2 x 2 linear system in I and y: - r = 2(0, - b +2(Q2-bzy-a7-a3+B+B (21) 12-1 =2(b1-C)+262 - czy-63++ . (2b) Since this is a system of linear equations, it can be expressed in matrix form, for some matrix and some vector on the right-hand side that you should be able to figure out. Your task in this part of the assignment is to implement this method in MATLAB (in gps2D. and gps 3D.m). That is, given the points A, B, C and distances TATB, TC, you will have to: 1. construct the matrix and the right-hand side vector in (3) corresponding to the linear system (21)-(2b), 2. pass this matrix and vector to the solve function (already provided in the zip file) to obtain the point P. Note: if you did not get your my rref function to work, you can change it to the MATLAB built-in rref in the solve function in solve.m. Exactly the same approach also works in 3D, except we will now need our distances from four known points A = (01.07.03), B = (b1,by.by), C = (01.. ), and D= (d.d2.dy). Your second task is to work out the analogous equations to (21)-(2b), and implement another program that works in 3D. Specification: function p = gpa2d(a, b, c, ra, rb, rc) Input: The 2D coordinates of three points A, B, C, and their distances Are re from an unknown point P. Output: The 2D coordinates of the point P. function P-gpa3d(a, b, c, d, ra, rb, rc, rd) Input: The 3D coordinates of four points A, B, C, D, and their distances TA 18 Tc, Tp from an unknown point P. Output: The 3D coordinates of the point P. Test cases: spa2([4;5), (5,-2), (-11;6], 5, 5, 13) should return the vector (1; 1). gps 30([6;-3;3), (-1;-6;5), (-5;4:7], [6;8;4), 5, 7, 9, 9) should re- turn (2:0:3). In general, you can create a random 2D vector with entries between say 0 and 10 by using a = 10*rand(2,1). Do this four times for a, b, c, and p, and set ra = norm(a - p) and so on. (The norm function returns the length of a vector.) Then check whether gps2d(a, b, c, ra, rb, rc) gives you back p
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
