Modify the functions for the bisection and false-position

Assignment Help MATLAB Programming
Reference no: EM13164798

Answer the following questions by modifying the scripts given at the bottom or creating new .m files is asked. Answer as many of the questions if possible.

1)Modify the functions for the bisection and false-position techniques of finding a root of an equation (see below questions) so that the number of iterations can be determined and displayed. (The count should only be displayed after the loop is completed, not for each iteration.) In the script file call your modified functions to determine the number of times the loop runs under the following conditions.

1.Use the bisection method with the equation f(x) = x3 +2x2 - x -2 with 0 and 1.3 as the guesses of the bracket and an error of 0.00001.

2.Use the false position method with the equation f(x) = x3 +2x2 - x -2 with 0 and 1.3 as the guesses of the bracket and an error of 0.00001.

3.Use the bisection method with the equation f(x) = x10 - 1 with 0 and 1.3 as the guesses of the bracket and an error of 0.00001.

4.Use the false position method with the equation f(x) = x10 - 1 with 0 and 1.3 as the guesses of the bracket and an error of 0.00001.

Plot both functions in the range of x from -0.5 to 1.4 with step of 0.02. Add comments to your script file that explain why there may be a difference in number of times the loop runs between two functions and the two methods. Hint: draw or print the two plots. Then by hand predict the first four or five new guesses for each algorithm. Think about how fast these new guesses are approaching the root in respect to the shape of the curve

Biscetion Function::::

function [root,calcerror] = bisrch(funct,low, high, error)

  •  function that uses bisection (sometimes called binary) search to find the
  •  root of the equation between low and high values
  •  input: function of x
  •  low which is the guess of the low value of x
  •  high which is the guess of the high value of x
  •  error which is the how close to 0 will be acceptable
  •  output: root - the value of x which evaluates to within the error
  •  calcerror - how far f(root is from 0)
  •  processing: Set number of roots = 0. Determine a middle value for
  •  x - xm=(low + high)/2 and calculate f(xm). If absolute
  •  value of f(xm)< error, set root = xm, set logical variable
  •  to false, and set nroot = 1. Else if sign of
  •  f(xm) = sign of f(low), then set low = xm. Otherwise set
  •  low = xm. Repeat until high-low < error or logical variable
  •  is false

notfound = true; % set logical variable to true
diff = (high-low); % calculate difference between high and low
nroot = 0; % set number of roots to 0


while (notfound & diff >0.00000001)
xm = (low + high)/2; % calculate middle value of x
fxm = funct(xm); % calculate f(xmiddle)
flow = funct(low); % calculate f(xlow)
if fxm == 0 | abs(fxm)< error % root found
root = xm;
nroot = 1;
notfound = false;
calcerror = abs(0 - fxm);
elseif sign(flow) == sign(fxm)
low = xm;
else
high = xm;
end % end if
diff = high - low;
end % end loop

if nroot == 0
disp('Root was not found in range given')
disp('Try again with new values')
root = [];
calcerror = [];
else
disp('A root was found')

end

False Position Function:::

function [fproot,zeroerror] = falsepos(func, low, high, accepterror)

  •  function to find the root of an equation using false position method and
  •  two guesses.
  •  input: function, low value for a guess, high value for a guess, and
  •  acceptable error for root.
  •  output: The root or an empty matrixif the root is not found.
  •  processing: Find a possibility for the root by creating a line between
  •  low value high value. New possibility is where the line
  •  intersects the x-axis. New possibility may be calculated by
  •  the equation
  •  xnew = xhigh - ((f(xhigh)(xlow -xhigh))/(f(xlow) - f(xhigh))
  •  Then f(xnew) will be calculated. If f(xnew) is equal to 0,
  •  set root to xnew and set logical variable to false.
  •  Otherwise compare the sign of f(xnew) is the same as the
  •  sign of low. If it the same, then set low to xnew,
  •  set high to xnew. Repeat until root is found or difference
  •  between xlow and xhigh is less than 0.0000001.

notfound = true;
diff = abs(high - low);
fproot =[];
while (notfound & diff > 0.00000001 )
flow = func(low);
fhigh = func(high);
xnew = high - ((fhigh)*(low - high))/(flow - fhigh);
fnew = func(xnew);
if abs(fnew) < accepterror
fproot = xnew;
notfound = false;
zeroerror = fnew;
elseif sign(fnew) == sign(flow)
low = xnew;
else
high = xnew;
end
diff = abs(high - low);

end

if notfound
disp('No roots were found in this range!')
disp('Try again with new guesses')
end

Reference no: EM13164798

Questions Cloud

The menu is displayed and the user must select : The menu is displayed and the user must select an option (a number between 0 and 7). The action corresponding to the selection is performed, then the menu is displayed again and the user can choose another option.
Compute the concentrations of fe : Calculate the concentrations of Fe3+ and SCN- in the reaction mixture in part I when you add 10.00 mL of 0.200 M Fe3+ to 1.00 mL of 2.0 x 10-3 M SCN- and make up the total volume to 50.00 mL? What is the concentration of FeSCN2+?
Create an er diagram using the set of requirements : Create an ER diagram using the set of requirements provided for Oxford City Council's bicycle sharing scheme and identify the minimal set of functional dependencies and all candidate keys for the relation R
What degrees celsius and pressure of hg occupy : What colume will 500 mL of gas at 20 degrees celsius and a pressure of 420 mm Hg occupy if the temperature is reduced to -80 degrees celsius
Modify the functions for the bisection and false-position : Modify the functions for the bisection and false-position techniques of finding a root of an equation (see below questions) so that the number of iterations can be determined and displayed. (The count should only be displayed after the loop is com..
Growing issues of women and larger cultural issues : The realities of women in the workplace and the growing issues of women and poverty are definitely major issues that the 21st century is confronting. Can we link these problems with larger cultural issues?
Estimate the vapor pressure of sea water : Estimate the vapor pressure of sea water at 20 degrees celsius given that the vapor pressure of pure water is 2.338 kPa at that temperature
Research business practices and labor issues : Research business practices and labor issues in Brazil, South Africa, Turkey, or Japan (choose one location). Discuss the advantages and disadvantages of planning a project in this country.
Presume a student attempts to do an ion exchange : suppose a student attempts to do an ion exchange on a column that is already nearly saturated with CO2+ and Zn2+.

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Import the data into matlab and name the array ace_data

Parameter is related to the energy of the storm, since kinetic energy is proportional to velocity squared. However, it does not take into account the size of the storm, which would be necessary for a true total energy estimate.

  Find the integral of a function at an arbitrary location

Write a Matlab function to perform numerical integration of a set of evenly spaced data points using the trapezoidal rule

  Create a matrix of 5x6

Prepare a matrix of 5x6. with identical columns and rows ranging from 200 to 1000 in equal increments

  Find general solution of the ordinary differential equation

Find a general solution of the following ordinary differential equations and find the general solution of the following ordinary differential equation

  Determine the optimal linear predictor

Determine the optimal linear predictor for a given order N and DPCM simulation and write a graphical user interface that has least the following functions

  Time domain design and analysis

To design a "custom" controller to reduce the vibrations of the seat and a PID controller to reduce the vibration of the seat

  Write a function named ''read_line''

Verify that your code works by saving some text into a file (created in notepad / textedit) and saving the file with extension '.txt'. You should attach the file (call it 'test.txt') with your code.

  First ten numbers of the sequence of pseudorandom numbers

write a program that gives the first ten numbers of the sequence of pseudorandom numbers

  Design and explain a computer-based simulation model

Design and explain a computer-based simulation model which you will use to estimate the probability that among 25, 50, 75, 100, 500, or 1000 randomly chosen people, at least 2 people share the same birthday.

  Open a named pipe and to read data from the pipe

Open a named pipe and to read data from the pipe in matlab

  Write matlab scripts

Write MATLAB scripts for to accept two numbers from the user; Display all prime numbers between these two numbers.

  Determine the size for variables used in matlab program

If b=3, a=6 how many loops would the given program do? what will be the out put for z(4)? what would be size (in rows and columns) for variables z, i and b?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd