Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a generic (i.e. non-problem specific) MATLAB function that implements the bisection method. The function should have the form function [xr,iter,x] Bisection(f, xl,xu,es,imax), where f

image text in transcribed

image text in transcribed

Write a generic (i.e. non-problem specific) MATLAB function that implements the bisection method. The function should have the form function [xr,iter,x] Bisection(f, xl,xu,es,imax), where f is a function handle (see below) that defines the root-finding problem f(x) -0,xl and xu are the lower and upper initial values, es is the stopping criterion for the relative approximate percent error defined in class, and imax is the maximum number of allowable iterations. The function outputs the value of the root (xr), the number of iterations used to calculate that root (iter), and a vector (X) of length iter containing the successive approximate root values at each iteration (i.e. the first element of X contains the approximation obtained at iteration 1, and the last element of X is X(iter) Use a while loop, and make sure that the number of times that the function f has to be evaluated is minimized At each iteration, the function should calculate the absolute value of the relative approximate percent error 4(as defined in class), starting with the second iteration (because two successive approximate root values are needed to compute .) At the end, the function should print the final root value (xr), the number of iterations used (iter), and the value of the relative approximate percent error for the last iteration in the command window in a nicely formatted way, using the fprintf command Finally, it should generate a plot of the absolute value of the relative approximate percent error |Ea| as a function of the iteration number (use a continuous line). The plot should have a grid, a title, and x and y labels. Since the magnitude of the error can vary greatly, plot it on a semi-logarithmic scale (see the semilogy command) A function handle for an anonymous function can be created in the MATLAB command window (or inside an M-file) using the following syntax (type help function_handle for more info): FUNHANDLE = @(ARGLIST ) EXPRESSION For example, typing y @(X) 1 + sqrt (X); creates the function y(x) = 1 + which can then be called in the following way: y(4) ans - 3 Use your function Bisection to solve the falling parachutist problem for the drag coefficient (I gave you the equationf(c) = 0 in class when I introduced the chapter on root- finding, and it is also described in Example 5.1 of the textbook, use m = 681 kg, v= 40 m.s1 t-10s and g = 9.81 m.s-2) with a stopping criterion of 0.01%, a maximum number of iterations of 100, and an initial interval of [12,16] Print the error plot and print the command window showing your formatted results (final root, number of iterations and relative percent approximate error) Finally, you will use your function to re-visit problem 1 of this assignment and to obtain the highest root. To do that, write a script called HW3_PB1. The script should define the function handle corresponding to problem 1, as well as all the necessary input parameters to call Bisection: use a stopping criterion of 106%, a maximum number of iterations of 100, and xl- 5, xu - 10. The script should then call Bisection, compute the absolute value of the true percent relative error led and plot l as a function of the iteration number on the same plot as the |Eal plot generated by the function, using a continuous line of a different color. Include a legend on your plot. Print the plot and print the command window showing your formatted results (final root, number of iterations and relative percent approximate error)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago