MAT2409 Assignment 3: USQ - Ellipse and Parabola Intersection Analysis

Verified

Added on  2022/12/30

|23
|2342
|54
Homework Assignment
AI Summary
This assignment solution for MAT2409 explores the intersection of an ellipse and a parabola using MATLAB. The student begins by plotting the two curves and identifying intersection points. The core of the assignment involves implementing the Jacobian method to find the intersection points for different values of the parameter 'p'. The solution includes MATLAB code for defining functions, calculating the Jacobian, and iterating to find the intersection points. The student modifies the code to calculate solutions for multiple 'p' values and then stores and displays iteration values of Jacobian and [x, y]. Finally, the solution plots the variation of intersection points with respect to 'p'. The assignment demonstrates a comprehensive understanding of numerical methods, curve analysis, and MATLAB programming.
Document Page
MAT2409 ASSIGNMENT 3
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1MAT2409 ASSIGNMENT 3
1. The given equation of ellipse is
x2+9 y2=16
x2
42 + 9 y2
42 =1
x2
42 + y2
(4/3)2 =1
The equation of the parabola is
y x2+2 x= p
Where, p = 0,1 and 2.
The two curves are plotted with intersection points as given by the following
MATLAB code.
MATLAB code:
x = -4:0.1:4;
y1 = sqrt((16 - x.^2)./9);
y2 = -sqrt((16 - x.^2)./9);
plot(x,y1,'b-')
hold on
plot(x,y2,'b-')
hold on
p1 = 0;p2 = 1; p3 = 2;
y3 = x.^2 - 2.*x + p1;
plot(x,y3)
Document Page
2MAT2409 ASSIGNMENT 3
y4 = x.^2 - 2.*x + p2;
plot(x,y4)
y5 = x.^2 - 2.*x + p3;
plot(x,y5)
ylim([-4 15])
hold on
legend('Ellipse plot +ve y-coordinates','Ellipse plot -ve y-coordinates','Parabola when
p=0','Parabola when p=1','Parabola when p=2')
intx = [-0.524 -0.154 0.429 1.488 2.068 2.435];
inty = [1.322 1.332 1.326 1.238 1.141 1.058];
plot(intx,inty,'bo')
grid on
legend('Ellipse plot +ve y-coordinates','Ellipse plot -ve y-coordinates','Parabola when
p=0','Parabola when p=1','Parabola when p=2','Intersection points')
Plot:
Document Page
3MAT2409 ASSIGNMENT 3
-4 -3 -2 -1 0 1 2 3 4
x range
-4
-2
0
2
4
6
8
10
12
14
y range
Ellipse plot +ve y-coordinates
Ellipse plot -ve y-coordinates
Parabola when p=0
Parabola when p=1
Parabola when p=2
Intersection points
Task 2:
Equation of ellipse is
f(x,y) = x^2 + 9y^2 – 16 = 0
g(x,y) = y – x^2 + 2x –p = 0
Now, the function is evaluated at given x,y and p values and its Jacobian is also
evaluated as given below.
MATLAB code:
function [f,g,J] = task2(x,y,p)
f = x^2 + 9*y^2 - 16; % ellipse function
g = y - x^2 + 2*x - p; % parabola function
J11 = (2*x); J12 = (18*y); % J11 = fx, J12 = fy
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4MAT2409 ASSIGNMENT 3
J21 = (-2*x + 2); J22 = (1); %J21 = gx, J22 = gy
J = [J11 J12;J21 J22]; % Jacobian evaluated at (x,y,p)
end
Output:
[f,g,J] = task2(1,1,1)
f =
-6
g =
1
J =
2 18
0 1
3. Now, a MATLAB function is written which returns the solution or intersection
(x,y) points based on the initial points by Jacobian method.
MATLAB code:
function [x,y] = task3(p)
xy=[2;1];
for k=1:6
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p];
Document Page
5MAT2409 ASSIGNMENT 3
J=[(2*x),(18*y);(-2*x + 2),1];
xy=xy-J\fg;
end
end
Output:
[x,y] = task3(0)
x =
2.4345
y =
1.0579
Hence, the program correctly calculated one intersection point for p=0 which can be
seen from previous plot.
4.
Now, the function is modified to calculate the solution for p=0, p=1 and p=2.
MATLAB code:
xy=[2;1];% initial guess is x = 2 and y = 1
p=0;
for k=1:10 % 10 iterations are used
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p];
Document Page
6MAT2409 ASSIGNMENT 3
J=[(2*x),(18*y);(-2*x + 2),1];
xy=xy-J\fg;
end
fprintf('The intersection of Ellipse and parabola for p=0 is [%.4f,%.4f] \n',x,y)
p=1;
xy=[x;y];
for k=1:10 % 10 iterations are used
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p];
J=[(2*x),(18*y);(-2*x + 2),1];
xy=xy-J\fg;
end
fprintf('The intersection of Ellipse and parabola for p=1 is [%.4f,%.4f] \n',x,y)
p=2;
xy=[x;y];
for k=1:10 % 10 iterations are used
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p];
J=[(2*x),(18*y);(-2*x + 2),1];
xy=xy-J\fg;
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7MAT2409 ASSIGNMENT 3
end
fprintf('The intersection of Ellipse and parabola for p=2 is [%.4f,%.4f] \n',x,y)
Output:
task4
The intersection of Ellipse and parabola for p=0 is [2.4345,1.0579]
The intersection of Ellipse and parabola for p=1 is [2.0683,1.1413]
The intersection of Ellipse and parabola for p=2 is [1.4875,1.2377]
5.
Now, the function is called once and for p = 0, 1, 2 all iteration values of J and [x,y] are
stored and displayed as given below.
MATLAB code:
function [J0,solx0,soly0,J1,solx1,soly1,J2,solx2,soly2] = task5()
xy=[2;1];% initial guess is x = 2 and y = 1
p=[0,1,2];
% For p = 0
for k=1:10 % 10 iterations are used
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p(1)];
J0(:,:,k)=[(2*x),(18*y);(-2*x + 2),1];
Document Page
8MAT2409 ASSIGNMENT 3
xy=xy-J0(:,:,k)\fg;
solx0(k) = xy(1);
soly0(k) = xy(2);
end
% For p = 1
xy=[solx0(end);soly0(end)];
for k=1:10 % 10 iterations are used
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p(2)];
J1(:,:,k)=[(2*x),(18*y);(-2*x + 2),1];
xy=xy-J1(:,:,k)\fg;
solx1(k) = xy(1);
soly1(k) = xy(2);
end
% For p = 2
xy=[solx1(end);soly1(end)];
for k=1:10 % 10 iterations are used
x=xy(1); y=xy(2);
fg=[x^2 + 9*y^2 - 16;y - x^2 + 2*x - p(3)];
Document Page
9MAT2409 ASSIGNMENT 3
J2(:,:,k)=[(2*x),(18*y);(-2*x + 2),1];
xy=xy-J2(:,:,k)\fg;
solx2(k) = xy(1);
soly2(k) = xy(2);
end
end
Output:
[J0,solx0,soly0,J1,solx1,soly1,J2,solx2,soly2] = task5()
J0(:,:,1) =
4 18
-2 1
J0(:,:,2) =
5.0500 18.9000
-3.0500 1.0000
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
10MAT2409 ASSIGNMENT 3
J0(:,:,3) =
4.8743 19.0386
-2.8743 1.0000
J0(:,:,4) =
4.8691 19.0428
-2.8691 1.0000
J0(:,:,5) =
4.8691 19.0428
-2.8691 1.0000
J0(:,:,6) =
Document Page
11MAT2409 ASSIGNMENT 3
4.8691 19.0428
-2.8691 1.0000
J0(:,:,7) =
4.8691 19.0428
-2.8691 1.0000
J0(:,:,8) =
4.8691 19.0428
-2.8691 1.0000
J0(:,:,9) =
4.8691 19.0428
chevron_up_icon
1 out of 23
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]