Computer Science Homework Solutions
Problem
#9089

Matlab program writing

writing program for Matlab where I find multiple roots using bisection, please see attachment

Attached file(s):
Attachments
program 7.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

program 7.doc


Where

= 4.47

= 1.875

= 19.25

and L. How can you verify that your algorithm has not missed any of
the roots? HINT: Consider the maximum frequency (dig back to that trig
you forgot) to help determine the size of an appropriate bracket for
this part of the problem.

I only understand the first sentence of these instructions. How do I
modify my program to find those 50 roots and, yes, how can I verify that
my algorithm has not missed any of the roots?

Also, could you please describe what each line of the main program is
doing? I understand the subprogram, ‘bisection,’ pretty well. I know
the two programs are similar.

Main Program (for finding first 10 roots of cos(5x))

function root=multibisection(func,j,xtol,ftol)

xlower=0;

xupper=xlower+j;

ylower=feval(func,xlower); %takes func and evaluates xlower into that
function

yupper=feval(func,xupper);

i=1;

while i<11

ylower=feval(func,xlower); %takes func and evaluates xlower into
that function

yupper=feval(func,xupper);

if abs(ylower)
root=xlower;

return

elseif abs(yupper)
root=xupper;

return

end

while (yupper*ylower)>0

xlower=xupper;

xupper=xlower+j;

yupper=feval(func,xupper);

ylower=feval(func,xlower);

end

b=bisection(func,xlower,xupper,xtol,ftol);

roots(i)=b;

i=i+1;

xlower=b+j;

xupper=xlower+j;

end

roots

format long

Sub Program

function root=bisection(func,xlower,xupper,xtol,ftol)

xroot=(xlower + xupper)/2;

yroot=feval(func,xroot);

count=0;

while abs(yroot)>ftol;

ylower=feval(func,xlower); %takes func and evaluates xlower into
that function

yupper=feval(func,xupper);

if ylower*yroot<0;

xupper=xroot;

yupper=yroot;

else

xlower=xroot;

ylower=yroot;

end



if abs(xupper-xlower)
root=xroot;

return

end

root=xroot;



xroot=(xlower + xupper)/2;

yroot=feval(func,xroot);



count=count + 1;

if count>500 %max number of iterations

count

range=xupper-xlower

disp ('too many interval halvings, stopping ...')

root=xroot

return

end

end %ends the while loop

Line4 m-file

function y=line4(x)

y=cos(5*x);

Testing:

>> multibisection(@line4,0.314,1e-11,1e-11)

roots =

Columns 1 through 4

0.31415926533914 0.94247779608140 1.57079632675968
2.19911485721864

Columns 5 through 8

2.82743338823505 3.45575191891333 4.08407044967386
4.71238898037956

Columns 9 through 10

5.34070751111268 5.96902604181838

PAGE

PAGE 2
Solution
What is this?
By OTA - Overall OTA Rating
Jie Xiong, MSc (IP) - 3.1/5
Purchase Cost Now
$2.19 CAD (was ~$7.98)
Included in Download
  • Plain text response
  • Attached file(s):
    • program.doc
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • MATLAB (must be coded for MATLAB) - I need a detailed script in order to show this works in MATLAB. ----> Kernighan and Ritchie, who created the C language, advise that, "The first program to write in any language is the same for al ...
  • Give pseudocode for the bisection method algorithm to find a zero of a continuous function. - A continuous function f(x) such that f(a) and f(b) have opposite signs, must have a zero (a point x such that f(x) = 0) in the interval [a, b]. Give a pseudocode for the bisection method algorithm ...
  • Matlab plotting cosh and sinh on a single plot using a script file - I have no idea what I'm doing. I got help writing a Matlab program that plots the cosh(3x-(pi/2)) and sinh(5x+(pi/8)) on a single plot from x=-5 to 25 using a script file. But could you please explain ...
  • MATLAB M-file creation - Write M-file to calculate the future value of an initial investment, or the amount that needs to be deposited annually to reach future investment goal. This program is to be written as a single M-fil ...
  • Matlab Program - In Matlab Develop a program that will: a. Calculate the integral of a n-order polynomial using Simpson's rule and rectangle rule, the orders will be positive integers. b. The user shall input the c ...
Browse