Matlab:Chapra , ROOTS [ Bracketing Method] Help needed.

  • Context: MATLAB 
  • Thread starter Thread starter uaeXuae
  • Start date Start date
  • Tags Tags
    Method Roots
Click For Summary

Discussion Overview

The discussion revolves around implementing the bracketing method, specifically the bisection method, in MATLAB to find roots of equations. Participants also explore the estimation of second derivatives using centered difference approximations, including comparisons with true values and theoretical calculations.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant seeks help with MATLAB implementation for finding roots using the bisection method.
  • Another participant asks for clarification on whether they should replace the function definition in the provided code with their specific equation.
  • A suggestion is made to modify the loop termination condition to achieve a desired error threshold.
  • A new problem is introduced regarding the estimation of the second derivative using centered difference approximations, with specific tasks outlined for evaluation and plotting.
  • Repeated requests for assistance in solving the second derivative estimation problem in MATLAB are noted.

Areas of Agreement / Disagreement

Participants generally agree on the approach to modify the bisection method code for their specific equations. However, the discussion on the second derivative estimation introduces new tasks without clear consensus on methods or solutions.

Contextual Notes

Participants have not fully resolved the specifics of implementing the second derivative estimation or the exact requirements for the MATLAB program submissions.

Who May Find This Useful

Students and practitioners interested in numerical methods for root-finding and derivative estimation using MATLAB may find this discussion beneficial.

uaeXuae
Messages
54
Reaction score
0
Hello guys can anyone help me solve this in MATLAB please ?


http://aycu34.webshots.com/image/43953/2003131790943491216_rs.jpg
 
Physics news on Phys.org
What are you having trouble with? Understanding the algorithm or implementing in Matlab?
 
Thanks for your reply. I am having trouble implementing the code into MATLAB and getting correct answers. May you guide me through please ?
 
If I had to find a zero of a simple function, say, x^2-3, using bisection, this is what I would write.

Code:
% bisection.m
function bisection
% find root of x^2 - 3 on some interval

xa = 0;         xb = 10;        % search interval

for it = 1:20           % loop
    xtest = xa + (xb-xa)/2;         % mid point of interval
    fa = f(xa);                     % left-interval function value
    fb = f(xb);                     % right-interval function value
    ftest = f(xtest);               % mid-point function value
    if sign(fa)*sign(ftest)<0       % if zero in left half
        xb = xtest;                 %   take left half of interval
    elseif sign(ftest)*sign(fb)<0   % if zero in right half
        xa = xtest;                 %   take right half of interval
    elseif ftest ==0                % if zero at mid-point
        break                       %   this is the zero
    else                            % 
        error('multiple roots or no root')  % may have no zero or multiple zeros
    end    
    xit(it) = xtest;                % store mid-points
end
figure;plot(xit)                    % plot mid-points, should converge to the root


function y = f(x)                   % function we're finding the root of
y = x^2-3;
 
Thanx a lot.

2 questions:

Q1) How do i input the equation ? Wherever it says "y = x^2-3" i replace it with the equation in the problem ?

Q2) how do i get an error<0.00005
 
uaeXuae said:
Q1) How do i input the equation ? Wherever it says "y = x^2-3" i replace it with the equation in the problem ?

Correct. Replace that with your equation. And you want to formulate the equation so you're finding a zero, so instead of finding x which solves f(x) = g(x), you want to find x which solves f(x) - g(x) = 0.

Q2) how do i get an error<0.00005

You want to change the condition for the loop to terminate. One possible way would be to define a quantity x_error = f(x_test), and when abs(x_error) < tolerance, then x_test is sufficiently close to the root. In that case you could do a 'while x_error < tolerance' loop.
 
Help needed. ( Could you please help me to solve this problem in matlab? thanks

(1) Use a centered difference approximation O(h2) to estimate the second derivative of the function .

(a) Perform the evaluation at x = 2 using step sizes of h = 0.2 and 0.1. Compare your estimates with the true value of the second derivative. Interpret your results on the basis of the remainder term of the Taylor series expansion.

(b) Write a Matlab program that evaluates the second derivative of the function (using a centered difference approximation O(h2)) on the interval [-4 , 4] with a step sizes of h = 0.2 and 0.1. Plot the second derivative of the function obtained by the centered difference method along with a graph obtained from a theoretical calculation.

Submit the solution of part (a) as a hard copy. For part (b), submit a fully functional program to the blackboard, and submit a copy of the program and accompanying figures as a hardcopy.
 
(1) Use a centered difference approximation O(h2) to estimate the second derivative of the function .

(a) Perform the evaluation at x = 2 using step sizes of h = 0.2 and 0.1. Compare your estimates with the true value of the second derivative. Interpret your results on the basis of the remainder term of the Taylor series expansion.

(b) Write a Matlab program that evaluates the second derivative of the function (using a centered difference approximation O(h2)) on the interval [-4 , 4] with a step sizes of h = 0.2 and 0.1. Plot the second derivative of the function obtained by the centered difference method along with a graph obtained from a theoretical calculation.

Submit the solution of part (a) as a hard copy. For part (b), submit a fully functional program to the blackboard, and submit a copy of the program and accompanying figures as a hardcopy.
 

Similar threads

Replies
6
Views
4K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K