1. Consider the following nonlinear system about xi, i = 1, 2, 3, 4:∫ x2 x1 sin(x3t 2 + x4)dt = −2.886389616512186e− 01,∫ x2 x1 cos(x3t 2 + x4)dt = 3.070929941495893e− 01,∫ x2 x1 tcos(x3t 2 + x4)dt =...

1 answer below »
There are 5 questions. Please use ode45,ode_rk33.m if it mention.


1. Consider the following nonlinear system about xi, i = 1, 2, 3, 4:∫ x2 x1 sin(x3t 2 + x4)dt = −2.886389616512186e− 01,∫ x2 x1 cos(x3t 2 + x4)dt = 3.070929941495893e− 01,∫ x2 x1 tcos(x3t 2 + x4)dt = 6.104465468269571e− 01, sin(x3x2 + x4) = −9.764160102906496e− 01. (a) Implement a Matlab function for f(x) and a Matlab function for its Jacobian Jf (x). In these Matlab function, use the composite Gauss-Legendre quadrature formula with 100 subintervals and 2 local nodes to compute all the integrals involved. Then, compute f(x(0)) and Jf (x (0)) with x(0) = [0.9; 2.5; 1.35; 1.6] and present the numerical results in the following table f1(x (0)) f3(x (0)) Jf (x (0))(1, 1) Jf (x (0))(2, 3) Jf (x (0))(4, 1) 1 yehong 附注 (b) Solve f(x) = 0 by Newton’s method started from x(0) = [0.9; 2.5; 1.35; 1.6]. Use tol = 10^(-10); nmax = 200; Present your solution in the following table: x1 x2 x3 x4 num of iterations used 2. The top profile of a noble beast is the graph of a piecewise function f(x) digitized into three data sets as follows: Piece 1: i 1 2 3 4 5 6 7 8 9 xi 1 2 5 6 7 8 10 13 17 f(xi) 3.0 3.7 3.9 4.2 5.7 6.6 7.1 6.7 4.5 f ′(xi) 1.0 -0.67 Piece 2: i 1 2 3 4 5 6 7 xi 17 20 23 24 25 27 27.7 f(xi) 4.5 7.0 6.1 5.6 5.8 5.2 4.1 f ′(xi) 3.0 -4.0 Piece 3: i 1 2 3 4 xi 27.7 28 29 30 f(xi) 4.1 4.3 4.1 3.0 f ′(xi) 0.33 -1.5 Instruction: Use the composite Gauss-Legendre formula with 50 subintervals and 3 local nodes to compute integrals in this problem. (a) Make a plot for the top profile of the noble beast by the clamped cubic spline. Scale the plot by 2 axis([0,30,0,30]) In addition, use cubic spline interpolants to find values of f(x) at x values specified by the following table and fill in the table the numerical results: x f(x) by the c-CS f(x) by the n-CS 10.5 20.5 28.5 where “c-CS” means the cubic spline with the clamped boundary condition and “n-CS” means the cubic spline with the natural boundary condition. (b) Find the length L for the 2nd piece of the graph of f(x) in the top profile of the noble beast. (c) In this part, we cut the 2nd piece of the graph of f(x) into three equal pieces. To do this, find x1, x2 ∈ [17, 27.7] such that the lengthes of the 2nd piece of the graph of f(x) over [17, x1], [x1, x2], and [x2, 27.7] are all equal to 1/3 of the length L found in Problem 2b. Present numerical results in the following table: x1 x2 Also, plot the points (xi, f(xi)), i = 1, 2 marked by ∗ together with the curve of for the top profile of the noble beast. Again, make sure to scale the plot by axis([0,30,0,30]) 3. Halley’s comet last reached perihelion (closest to the sun) on February 9th, 1986. Its position and velocity components at this time were xy z  =  0.325514−0.459460 0.166229  ,  x′y′ z′  =  −9.096111−6.916686 −1.305721  where the position is measured in astronomical units (the earth’s mean distance from the sun), and the time in years. The equations of motion for the comet are x′′(t) = − µx(t) (r(t))3 , y′′(t) = − µy(t) (r(t))3 , z′′(t) = − µz(t) (r(t))3 , 3 where r(t) = √ (x(t))2 + (y(t))2 + (z(t))2, µ = 4π2, and r(t) is distance between the comet and the sun. (a) Solve the IVP of the first order system found above in the interval t ∈ [0, 100] (t = 0 was the year of 1986) by the adaptive method (ode45 from Matlab). Set up the parameters for the ode45 ODE solver as follows options = odeset(’RelTol’,1e-8,’AbsTol’,1e-8); Present numerical results in the following table: x(100) y′(100) z′′(100) (b) i. Use the numerical solution produced in Problem 3a and the cubic spline inter- polation with the clamped boundary condition to find the position of Halley’s comet at t∗ when the next closest approach of the comet to the sun. Present your script for computing t∗ and present the numerical results in the following table: x(t∗) y(t∗) z(t∗) ii. Use Matlab’s plot3 program to plot the trajectory of the comet together with the position of the sun (x = 0, y = 0, z = 0) and the position of the comet at the time t∗ found above. Instructions for this plot: • Mark the sun by a red ∗ and mark the position of the comet at the time t∗ by a blue ∗. • Adjust the plot by view(-97.92, 23.64) (c) Then compute the area between the curve of y(t) and the curve of z(t) over the interval t ∈ [70, 80]. Use the numerical solution generated in Problem 3a and the cubic spline interpolation with the clamped boundary condition to represent functions y(t) and z(t) in this task. 4. This problem is to solve the following BVP (Boundary Value Problem) of a 4th order differential equation by the shooting method: u′′′′(x) = f(x, u(x), u′(x), u′′(x), u′′′(x)), x ∈ (a, b), (1) u(a) = b1, u ′(a) = b2, u(b) = b3, u ′(b) = b4. (2) 4 (a) Consider the related IVP (Initial Value Problem): u′′′′(x) = f(x, u(x), u′(x), u′′(x), u′′′(x)), x ∈ (a, b], (3) u(a) = b1, u ′(a) = b2, u ′′(a) = y1, u ′′′(a) = y2. (4) For the following specific data: f(x, u(x), u′(x), u′′(x), u′′′(x)) = 32cos(x)sin(x)− 2cos(cos(2x))sin(cos(2x)) + sin(u′(x)), a = 1, b = 2, b1 = 0.9, b2 = −0.8, y1 = −3.6, y2 = 3.3, use ode_rk33.m with Nh = 100 to solve the IVP described by equations (3) and (4). Present the numerical solution in a table as follows: x 1.22 1.67 u(x) u′(x) u′′(x) u′′′(x) (b) Consider the following function: F(y) = [ F1(y1, y2) F2(y1, y2) ] = [ u(b)− b3 u′(b)− b4 ] , with y = [ y1 y2 ] , where u(x) is the solution to the IVP described by equations (3) and (4), b3, b4 are specified in the boundary condition of the BVP described by equations (1) and (2). Implement this function in Matlab with the following interface: function F = two_point_ShMeth_beam_nonlinearF(y, f_fun, a, b, ... b1, b2, b3, b4, Nh, varargin) In this Matlab function, use ode_rk33.m to solve for u(x) from the IVP described by equations (3) and (4). The inputs f_fun, a, b, b1, b2, b3, b4 are from the BVP, Nh is for the ODE solver ode_rk33.m. Then, use the BVP described by equations (1) and (2) to test the Matlab two_point_ShMeth_beam_nonlinearF.m with f(x, u(x), u′(x), u′′(x), u′′′(x)) = 32cos(x)sin(x)− 2cos(cos(2x))sin(cos(2x)) + sin(u′(x)), a = 1, b = 2, b1 = 0.1, b2 = 0.15, b3 = 0.2, b4 = 0.25. 5 For y = [ 0.1 0.3 ] and Nh = 100, this Matlab function can produce F(y) = [ 6.281888141405834e− 01 1.849268826683720e+ 00 ] The acceptable answer to this problem, i.e. Problem 4b should contain the Matlab function two_point_ShMeth_beam_nonlinearF.m, the script to compute F(y), and a statement such as This Matlab function of mine reproduces F(y) given above (c) Use the shotting method to solve the BVP described by equations (1) and (2) with f(x, u(x), u′(x), u′′(x), u′′′(x)) = 32cos(x)sin(x) −2cos(u′′(x))sin(u(x)) + sin(u′(x)), a = 1, b = 2, b1 = 0.1, b2 = 0.15, b3 = 0.2, b4 = 0.25. Note that function f(x, u(x), u′(x), u′′(x), u′′′(x)) is different from the one in the previous subproblems. Present your script for the related computations and present numerical solution in the following table: x 1.21 1.65 u(x) u′(x) u′′(x) u′′′(x) 5. Consider the following BVP for the steady state Burgers equation: −y′′(x) + µy(x)y′(x) = f(x), x ∈ (0, 1), y(0) = α, y(1) = β. (a) Derive the finite difference equations for this BVP on a set of equispaced nodes: a = x1 < x2="">< ·="" ·="" ·="">< xn = b, h = xi − xi−1, i = 2, 3, · · · , n. then describe the vector format f(u) = 0 for this system of finite difference equations by identifying the component functions of f(u). (b) implement a matlab function for f(u) and a matlab function for jf(u). the interfaces of these maltab functions should be as follows: 6 function f = two_point_nl_f(u, x, f_fun, alpha, beta) function j = two_point_nl_fj(u, x, f_fun, alpha, beta) (c) write a matlab script that uses both the newton method and broyden method to solve the finite difference equation for the burgers equation with the following data: f(x) = −ex−2x2 ( xex ( − 1− x+ 2x2 ) + ex 2( 2− 5x− 4x2 + 4x3 )) , µ = 1, α = 0, β = 1, h = 0.002. present numerical results in the following table: method number of iterations y(0.45) broyden newton some instructions for these computations: • use tol = 10^(-8) and nmax = 100 for stopping the iterations. • use the approximate jacobian by the complex variable method for the initial matrix b0 required by the broyden’s method. • try the linear approximation as the initial guess for solving f(u) = 0. (d) write a matlab script that uses the numerical solution generated in problem 5c and a suitable interpolation method to find an approximation to y(2/π). jus- tify your choice of the interpolation method and the related data for computing this approximation to y(2/π) from the point of view of both the accuracy and efficiency. 7 xn="b," h="xi" −="" xi−1,="" i="2," 3,="" ·="" ·="" ·="" ,="" n.="" then="" describe="" the="" vector="" format="" f(u)="0" for="" this="" system="" of="" finite="" difference="" equations="" by="" identifying="" the="" component="" functions="" of="" f(u).="" (b)="" implement="" a="" matlab="" function="" for="" f(u)="" and="" a="" matlab="" function="" for="" jf(u).="" the="" interfaces="" of="" these="" maltab="" functions="" should="" be="" as="" follows:="" 6="" function="" f="two_point_nl_F(u," x,="" f_fun,="" alpha,="" beta)="" function="" j="two_point_nl_FJ(u," x,="" f_fun,="" alpha,="" beta)="" (c)="" write="" a="" matlab="" script="" that="" uses="" both="" the="" newton="" method="" and="" broyden="" method="" to="" solve="" the="" finite="" difference="" equation="" for="" the="" burgers="" equation="" with="" the="" following="" data:="" f(x)="−ex−2x2" (="" xex="" (="" −="" 1−="" x+="" 2x2="" )="" +="" ex="" 2(="" 2−="" 5x−="" 4x2="" +="" 4x3="" ))="" ,="" µ="1," α="0," β="1," h="0.002." present="" numerical="" results="" in="" the="" following="" table:="" method="" number="" of="" iterations="" y(0.45)="" broyden="" newton="" some="" instructions="" for="" these="" computations:="" •="" use="" tol="10^(-8)" and="" nmax="100" for="" stopping="" the="" iterations.="" •="" use="" the="" approximate="" jacobian="" by="" the="" complex="" variable="" method="" for="" the="" initial="" matrix="" b0="" required="" by="" the="" broyden’s="" method.="" •="" try="" the="" linear="" approximation="" as="" the="" initial="" guess="" for="" solving="" f(u)="0." (d)="" write="" a="" matlab="" script="" that="" uses="" the="" numerical="" solution="" generated="" in="" problem="" 5c="" and="" a="" suitable="" interpolation="" method="" to="" find="" an="" approximation="" to="" y(2/π).="" jus-="" tify="" your="" choice="" of="" the="" interpolation="" method="" and="" the="" related="" data="" for="" computing="" this="" approximation="" to="" y(2/π)="" from="" the="" point="" of="" view="" of="" both="" the="" accuracy="" and="" efficiency.="">
Answered Same DayDec 02, 2021

Answer To: 1. Consider the following nonlinear system about xi, i = 1, 2, 3, 4:∫ x2 x1 sin(x3t 2 + x4)dt =...

Kshitij answered on Dec 08 2021
154 Votes
HW_9/Code_1.m
%% Problem no.1 (b)
% clear screen
clc
clear all
%% Newtons's Method to solve non linear equation
% initial guess
x0=[0.9;2.5;1.35;1.6];
% tol
tol = 10^-10;
% maximum iteration
nmax = 200;
% subintervals
N=100;
% anomly. function
J =@(x) gauss_J(x);
F =@(x) gauss_F(x,N);
x1 = x0;
n=0;
delF=1;
while tol x2 = x1 - inv(J(x1)) * F(x1);
x1=x2;
n=n+1;
end
for i=1:4
fprintf('x%d = %10.3f\n'
,i,x1(i))
end
fprintf('No. of iteration: %d\n',n)
HW_9/Code_2.m
%% Problem no. 2
% clear screen
clc
clear all
%% piece 1 clamped boundary conditions 1 to -0.67
t1 = [1 2 5 6 7 8 10 13 17];
y1 = [3 3.7 3.9 4.2 5.7 6.6 7.1 6.7 4.5];
cs1 = spline(t1,[1 y1 -0.67]);
xx = linspace(1,17,50);
plot(t1,y1,'or',xx,ppval(cs1,xx),'-');
hold on
%% piece 2 clamped boundary conditions 3 to -4.0
t2 = [17 20 23 24 25 27 27.7];
y2 = [4.5 7.0 6.1 5.6 5.8 5.2 4.1];
cs2 = spline(t2,[3 y2 -4]);
xx = linspace(17,27.7,50);
plot(t2,y2,'or',xx,ppval(cs2,xx),'-');
hold on
%% piece 3 clamped boundary conditions 0.33 to -1.5
t3 = [27.7 28 29 30];
y3 = [4.1 4.3 4.1 3.0];
cs3 = spline(t3,[0.33 y3 -1.5]);
xx = linspace(27.7,30,50);
plot(t3,y3,'or',xx,ppval(cs3,xx),'-');
axis([0,30,0,30])
grid on
%% f(x) by the c-CS
disp('c-CS')
fprintf('\nat x = 10.5, f(x) is %5.2f\n',ppval(cs1,10.5))
fprintf('\nat x = 20.5, f(x) is %5.2f\n',ppval(cs2,20.5))
fprintf('\nat x = 28.5, f(x) is %5.2f\n',ppval(cs3,28.5))
%% cubic spline natural boundary condition
pp1 = csape(t1,y1,'variational');
figure;
fnplt(pp1)
hold on
pp2 = csape(t2,y2,'variational');
fnplt(pp2)
pp3 = csape(t3,y3,'variational');
fnplt(pp3)
%% f(x) by the n-CS
disp('n-CS')
fprintf('\nat x = 10.5, f(x) is %5.2f\n',ppval(pp1,10.5))
fprintf('\nat x = 20.5, f(x) is %5.2f\n',ppval(pp2,20.5))
fprintf('\nat x = 28.5, f(x) is %5.2f\n',ppval(pp3,28.5))
%% part (b)
% lenght L for the 2nd piese of graph
ln2=0;
for i=1:numel(t2)-1
ln2 = sqrt((t2(i+1)-t2(i)).^2 + (y2(i+1)-y2(i)).^2)+ln2;
end
fprintf('\nLength L for 2nd piece : %0.3f\n',ln2)
%% part (c)
pt=linspace(17,27.7,4);
% mark the points
plot(pt(2),7.08,'.r','markersize',20)
plot(pt(3),5.59,'.r','markersize',20)
fprintf('x1 = %0.2f\n',pt(2))
fprintf('x2 = %0.2f\n',pt(3))
HW_9/Code_3.m
%% Problem 3. Halley's comet trajectory
% clear screen and close figure
clc
clear all
close all
%% solving IVP
tSpan=[0 100];
y0=[0.325514 -9.096111 -0.459460 -6.916686 0.166229 -1.305721];
options = odeset('RelTol',1e-8,'AbsTol',1e-8);
[tSol,ySol]=ode45(@cometa,tSpan,y0,options);
figure;
plot3(0,0,0,'*r','markersize',14)
hold on
plot3(ySol(:,1),ySol(:,3),ySol(:,5),'*b','markersize',2)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Trajectory Halley''s Comet')
view(-97.92,23.64)
%% t for halley's comet close to sun
rdi = sqrt(ySol(:,1).^2+ySol(:,3).^2+ySol(:,5).^2);
[rdi,Idx] = min(rdi);
disp('position of comet the time t*')
fprintf('x = %0.2f, y = %0.2f & z = %0.2f\n',ySol(Idx,1),ySol(Idx,3),ySol(Idx,5))
%% compute area between curve y and z tE(70,80)
Areay=trapz(ySol([830:1:948],3));
Areaz=trapz(ySol([830:1:948],5));
fprintf('\nArea between the curve : %0.3f\n',abs(Areay-Areaz))
%% function for calculating trajectory of comet
function dYdt=cometa(~,Y)
r=sqrt((Y(1).^2+Y(3).^2+Y(5).^2));
dxdt=Y(2);
dvxdt=-4*pi^2.*Y(1)./r.^3;
dydt=Y(4);
dvydt=-4*pi^2.*Y(3)./r.^3;
dzdt=Y(6);
dvzdt=-4*pi^2.*Y(5)./r.^3;
dYdt=[dxdt;dvxdt;dydt;dvydt;dzdt;dvzdt];
end
HW_9/gauss_F.m
%% Problem no.1 part(a)
function F=gauss_F(x,n)
% limits
a=x(1);
b=x(2);
% range
lim=linspace(a,b,n);
% eq 1
I1=0;
for i=1:numel(lim)-1
f1=@(t) sin(x(3)*(0.5*(lim(i+1)+lim(i))+0.5*(lim(i+1)-lim(i))*t)^2+x(4));
I1 = 0.5*(lim(i+1)-lim(i))*(f1(-1/sqrt(3))+f1(1/sqrt(3)))+I1;
end
I1=I1+2.886389616512186e-1;
% eq 2
I2=0;
for i=1:numel(lim)-1
f2=@(t) cos(x(3)*(0.5*(lim(i+1)+lim(i))+0.5*(lim(i+1)-lim(i))*t)^2+x(4));
I2 = 0.5*(lim(i+1)-lim(i))*(f2(-1/sqrt(3))+f2(1/sqrt(3)))+I2;
end
I2=I2-3.0709299414495893e-1;
% eq 3
I3=0;
for i=1:numel(lim)-1
f3=@(t) t*cos(x(3)*(0.5*(lim(i+1)+lim(i))+0.5*(lim(i+1)-lim(i))*t)^2+x(4));
I3 = 0.5*(lim(i+1)-lim(i))*(f3(-1/sqrt(3))+f3(1/sqrt(3)))+I3;
end
I3=I3-6.104465468269571e-1;
% eq 4
I4 = sin(x(3)*x(2)+x(4))+9.76416010290649e-1;
% Function
F=[I1;I2;I3;I4];
end
HW_9/gauss_J.m
%% Problem No. 1 (a)
function J=gauss_J(x)
% jacobian of non linear function
J = [(x(1)/2 - x(2)/2)*(x(3)*cos(x(3)*(x(1)/2 + x(2)/2 - (3^(1/2)*(x(1)/2 - x(2)/2))/3))*(3^(1/2)/6 - 1/2) - x(3)*cos(x(3)*(x(1)/2 + x(2)/2 + (3^(1/2)*(x(1)/2 - x(2)/2))/3))*(3^(1/2)/6 + 1/2)) - sin(x(3)*(x(1)/2 + x(2)/2...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here