Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a matlab function sol =solveEq (a) .that uses the bisection method to find all solutions to the equaton ax+2 = e x accurate within

write a matlab function sol =solveEq (a) .that uses the bisection method to find all solutions to the equaton ax+2 = ex

accurate within 10 decimals. test your program with at least 3 different values of a. Asample output could look as follwos (your answer may vary due to your choice of brackting intervals):

>> [sol, steps] =solveEq (0)

sol =

0.693147180559945

steps =

0

>> [sol, steps] =solveEq (-5)

sol =

0.164289021364685

steps =

33

>> [sol, steps] =solveEq (5)

sol =

-0.243172799230088 2.760014541896950

steps =

32 34

-------------------------------------------------------------------------------------------------------------

here

bisect.m

%Program 1.1 Bisection Method %Computes approximate solution of f(x)=0 %Input: inline function f; a,b such that f(a)*f(b)<0, % and tolerance tol %Output: Approximate solution xc function xc = bisect(f,a,b,tol) if sign(f(a))*sign(f(b)) >= 0 error('f(a)f(b)<0 not satisfied!') %ceases execution end fa=f(a); fb=f(b); k = 0; while (b-a)2>tol c=(a+b)/2; fc=f(c); if fc == 0 %c is a solution, done break end if sign(fc)*sign(fa)<0 %a and c make the new interval b=c;fb=fc; else %c and b make the new interval a=c;fa=fc; end end xc=(a+b)/2; %new midpoint is best estimate

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

1. Prepare a flowchart of Dr. Mahalees service encounters.

Answered: 1 week ago