Docsity

Quiz 7 with Solution - Computational Methods | CMSC 460, Quizzes of Computer Science

Toggle sidebar
bg1
AMSC/CMSC 460 Quiz 7 ,Fall 2007
1. (10) Write Matlab code to use fzero to find an approximate solution to
the problem
F(x) = Zx
0
g(t)dt = 5.
You may assume that there is a Matlab function g.m that evaluates g(t),
that F(1) <5 and that F(2) >5. Recall that fzero finds a point xso that
f(x) = 0. It takes two arguments: the first defines the function fand the
second is a vector of length 2 where fevaluated at the first component differs
in sign from fevaluated at the second.
Answer:
x = fzero(@F,[1,2]);
function y = F(x)
y = quad(@g,0,x) - 5;
2. (10) Apply one step of Newtonโ€™s method to solve the nonlinear equation
๎˜”x2
1+x2
2โˆ’1
cos(x2)๎˜•=๎˜”0
0๎˜•
using a starting guess of x1= 1/2, x2=ฯ€/4. Your answer should be either
two numbers (the values of x1and x2after the iteration), or computable
formulas that Matlab could use to get these numbers.
(Recall that cos(ฯ€/4) = sin(ฯ€/4) = โˆš2/2.)
Answer: The Jacobian matrix is
J(x) = ๎˜”2x12x2
0โˆ’sin(x2)๎˜•.
Therefore, one step of Newtonโ€™s method computes
xโ†xโˆ’J(x)\๎˜”x2
1+x2
2โˆ’1
cos(x2)๎˜•,
or
xโ†๎˜”1/2
ฯ€/4๎˜•โˆ’๎˜”1ฯ€/2
0โˆ’โˆš2/2๎˜•\๎˜”1/4+(ฯ€/2)2โˆ’1
โˆš2/2๎˜•.
1

Partial preview of the text

Download Quiz 7 with Solution - Computational Methods | CMSC 460 and more Quizzes Computer Science in PDF only on Docsity!

AMSC/CMSC 460 Quiz 7 , Fall 2007

  1. (10) Write Matlab code to use fzero to find an approximate solution to the problem

F (x) =

โˆซ (^) x

0

g(t)dt = 5.

You may assume that there is a Matlab function g.m that evaluates g(t), that F (1) < 5 and that F (2) > 5. Recall that fzero finds a point x so that f (x) = 0. It takes two arguments: the first defines the function f and the second is a vector of length 2 where f evaluated at the first component differs in sign from f evaluated at the second.

Answer:

x = fzero(@F,[1,2]);

function y = F(x) y = quad(@g,0,x) - 5;

  1. (10) Apply one step of Newtonโ€™s method to solve the nonlinear equation [ x^21 + x^22 โˆ’ 1 cos(x 2 )

]

[

]

using a starting guess of x 1 = 1/2, x 2 = ฯ€/4. Your answer should be either two numbers (the values of x 1 and x 2 after the iteration), or computable formulas that Matlab could use to get these numbers. (Recall that cos(ฯ€/4) = sin(ฯ€/4) =

Answer: The Jacobian matrix is

J(x) =

[

2 x 1 2 x 2 0 โˆ’ sin(x 2 )

]

Therefore, one step of Newtonโ€™s method computes

x โ† x โˆ’ J(x)\

[

x^21 + x^22 โˆ’ 1 cos(x 2 )

]

or

x โ†

[

ฯ€/ 4

]

[

1 ฯ€/ 2 0 โˆ’

]

\

[

1 /4 + (โˆšฯ€/2)^2 โˆ’ 1 2 / 2

]