Question
last digit is 5
2(a) Let d be the last digit of your student ID number. But if d0, take d6. Then in Example 1.1 of Chapter 4, suppose we want
bisect
function [n,alpha]-bisect (a,b,eps) alpha-(a+b)/2 n-1i fval-f (alpha); while (b-alpha> eps) & (fval0) fa-f (a) if fa*fval< 0
f.m
function y=f(w) y=cos ( w )-w ; end
newton.m

function [n,alpha ] newton (x0,eps, maxits) alpha-x0; [fval,deriv]-func (alpha); n 0; while ( abs ( fval ) > eps ) & ( n <= m
func.m

function [f,fdash]=func (W) f=cos (w)-w ; fdash--sin(w)-1; end
2(a) Let d be the last digit of your student ID number. But if d0, take d6. Then in Example 1.1 of Chapter 4, suppose we want v(12)d, that is, g(e24-I) With g-9.8, use the bisection method as implemented in the Matlab function bisect in bisect.m with error tolerance eps 108 to find an approximation to . Please hand in an explanation of how your a and b were found as well as the last ten approximations from the bisection method if it took at least 10 iterations or all the approximations if it took fewer than ten. You should set format long before invoking the function by typing bisect (a,b, eps). A sample f.m file containing the function f required by bisect is also available from Moodle. The function f is currently set to cos()-in f.m. Note that the function in the bisect.m file on Moodle is slightly different from the one given in Section 8 of the Matlab notes in that the version on Moodle will output to the screen the approximations as they are calculated and also gives the number of iterations at the end in the variable ans (b) Repeat part (a), but this time use the Newton-Raphson method in the function newton in newton.m. The input parameters are the initial value x0, error tolerance eps, and maximum number of iterations max its. You should take eps-10-8 and maxit s = 10 The function may be invoked from Matlab by typing newton (x0, eps, maxits) The output to the screen are the approximations as they are calculated and the variable ans at the end is the number of iterations required. A sample func.m file containing the function func required by newton is also available from Moodle. The function func is where f(o) and f.,(ω) are defined and currently is for f(o) = cos(ω)-ω. In Matlab, the command for ex s exp ( x) . Please hand in your expression for "f,(w), an explanation of how you chose x0, as well as all the approximations. (c) From your numerical results, which of the two methods above seemed to be the better method?
function [n,alpha]-bisect (a,b,eps) alpha-(a+b)/2 n-1i fval-f (alpha); while (b-alpha> eps) & (fval0) fa-f (a) if fa*fval eps ) & ( n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

Bisect

function [n,alpha]=bisect(a,b,eps)

alpha=(a+b)/2;

n=1;

fval=f(alpha);

while (b-alpha> eps) & (fval ~= 0)

fa=f(a);

if fa*fval< 0

b=alpha;

else

a=alpha;

end

alpha=(a+b)/2;

n=n+1;

fval=f(alpha);

end

end

newton

function [n,alpha]=newton(x0,eps,maxits)

alpha=x0;

[fval,deriv]=func(alpha);

n=0;

while (abs(fval) > eps) & (n <= maxits)

alpha=alpha-fval/deriv;

n=n+1;

[fval,deriv]=func(alpha);

end

end

f

function y=f(w)

%i am assuming d=6 you can change it in the line below

d=6;

y=9.8*(exp(24*w)-1)/(w*(exp(24*w)+1))-d;

end

func

function [f,fdash]=func(w)

d=6;

f=9.8*(exp(24*w)-1)/(w*(exp(24*w)+1))-d;

fdash=9.8*(24*(exp(24*w)*(w*(exp(24*w)+1)))-(exp(24*w)-1)*((exp(24*w)+1)+w*(exp(24*w)*24)))/((w*(exp(24*w)+1))^2);

end

>> format long [n,ans]-bisect(-2,1,10 (-8)) n- 29 ans 1.633333338424563

[n, ans]-newton(- .5,104-8,500e) >> n- fi ans 1.633333333220014

function [n,alpha]-newton(xe, eps,maxits) alpha-xe; [fval, deriv-func (alpha); n=0 ; while (abs(fval) > eps) & (n <= alpha-alFunction [f,fdash1-func (w) d-6; f-9.8* (exp(24%)-1)/(w* ( exp(24%) +1))-d; fdash-9.8*( 24(exp(24w) (w(exp(24w)+1)))-(ex1 function y-f(w) %i am assuming d-6 you can change it in the line below 3-d-6; y-9.8* (exp(24%)-1)/(w*(exp(24%)+1))-d; 4- 5efunction [n,alpha]-bisect (a,b,eps) alpha-(a+b)/2; 1 n=1; fval-f (alpha); while (b-alpha» fa-f(a); & (fva1 5-[ eps) e) ~= if

Add a comment
Know the answer?
Add Answer to:
last digit is 5 bisect f.m newton.m func.m 2(a) Let d be the last digit of your student ID number. But if d0, t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT