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
  • Hi, we recently had an assignment and I ended up skipping this question because I didn't understand the question nor...

    Hi, we recently had an assignment and I ended up skipping this question because I didn't understand the question nor how to even start it. Obviously for Matlab! Coding is not my strong point so this was a stitch up. The data we were meant to use is below! For (a) 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 Sample f.m function y=f(w)...

  • in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge wh...

    in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge when using Function 4.3.1? Is the root obtained the one that is closest to that guess? )xo = 1.5, (b) x0 = 2, (c) x.-3.2, (d) xo = 4, (e) xo = 5, (f) xo = 27. Function 4.3.1 (newton) Newton's method...

  • ____________ % This function is a modified versio of the newtmult function obtained % from % “Ap...

    ____________ % This function is a modified versio of the newtmult function obtained % from % “Applied Numerical Methods with MATLAB, Chapra, % 3rd edition, 2012, McGraw-Hill.” function [x,f,ea,iter]=newtmult(func,x0,es,maxit,varargin) % newtmult: Newton-Raphson root zeroes nonlinear systems % [x,f,ea,iter]=newtmult(f,J,x0,es,maxit,p1,p2,...): % uses the Newton-Raphson method to find the roots of % a system of nonlinear equations % input: % f = the passed function % J = the passed jacobian % x0 = initial guess % es = desired percent relative error...

  • This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...

    This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable to transcribe this imageNewton's Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson method (Newton's method) is another iterative root-finding method. The method is geometrically motivated and uses the derivative to find roots. It has the advantage that it is very fast (generally faster than bisection) and works on problems with double (repeated) roots, where the...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

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