EE 221 Computing for Engineers Homework #10 Problem #1 (30 points): Let the math
ID: 2249207 • Letter: E
Question
EE 221 Computing for Engineers Homework #10 Problem #1 (30 points): Let the mathematical function f(x) be defined as: f(x)-exp(-0.5x) cos(10x) Write a Matlab function called Newton1 that would find the zero based on a passing input argument x0. The function should starts as: function x:Newton!(XO) % enter your code here end Submit the function as a.m file. Apply different initial guesses to find the zero (0, 0.1, 0.2, 0.3 &0.4). Hint: the while loop should have the following statement while((abs(fx)>5 eps)ll(abs(dx)>5'eps)l (n10000)) %where n is the iteration number end Problem #2 (20 points): a) Let the mathematical function f(x) be defined as: f(x) - exp(-0.5x) cos(10x) Use fzero) to find the zero of fx) x0-0.1. b) Find the roots of the following polynomial using roots command g(x) =x4-2x3 +x-5 Submit the script as a.m file. (Note: Script is a list of commands which is different from functions)Explanation / Answer
Matlab Script:
function x = Newton1(x0)
n=0;
x_prev = x0;
fx = exp(-0.5*x_prev)*cos(10*x_prev);
dx = 0;
while (abs(fx)>5*eps)||(abs(dx)>5*eps)||n<10000
xn = x_prev-((exp(-0.5*x_prev)*cos(10*x_prev)))/(exp(-0.5*x_prev)*((-0.5*cos(10*x_prev))-(10*sin(10*x_prev))));%xn+1 = xn-(fx/f'x)
n = n+1;
dx = xn-x_prev;%dx = x(n) - x(n-1)
x_prev = xn;
fx = exp(-0.5*x_prev)*cos(10*x_prev);
end
x = x_prev;
end
command window output:
>> clear all
>> x = Newton1(0)
x =
2.0420
>> exp(-0.5*x)*cos(10*x)
ans =
-3.5314e-016
>> x = Newton1(0.1)
x =
0.1571
>> exp(-0.5*x)*cos(10*x)
ans =
5.6607e-017
>> x = Newton1(0.2)
x =
0.1571
>> exp(-0.5*x)*cos(10*x)
ans =
5.6607e-017
>> x = Newton1(0.3)
x =
-0.7854
>> exp(-0.5*x)*cos(10*x)
ans =
4.5342e-016
>> x = Newton1(0.4)
x =
0.4712
>> exp(-0.5*x)*cos(10*x)
ans =
-1.4514e-016
>>
Problem 2:
>> clear all
>> fun = @(x) exp(-0.5*x)*cos(10*x)
fun =
@(x)exp(-0.5*x)*cos(10*x)
>> x0 = 0.1
x0 =
0.1000
>> x = fzero(fun,x0)
x =
0.1571
>>
above value is same as that we obtained in question 1 for initial guess 0.1
%part b
given polynomial can be writtien into vector form as
>> gx = [1 -2 0 1 -5]
gx =
1 -2 0 1 -5
>> roots(gx)%roots function is used to find the roots of a given polynomial in vector form
ans =
2.2439
0.5000 + 1.2415i
0.5000 - 1.2415i
-1.2439
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.