Bisection Method | Programming Numerical Methods in MATLAB

Поделиться
HTML-код
  • Опубликовано: 17 сен 2024
  • The algorithm and #MATLAB #programming steps of finding the roots of a nonlinear equation by using the bisection method are explained in this #tutorial.
    Get the FREE ebook: mechtutor.thin...
    Get the ebook of this method and many more with code files on this webpage: mechtutor.thin...
    MATLAB Quick Reference - ebook link: mechtutor.thin...
    Visit my new Python course webpage: mechtutor.thin...
    Credits:
    Musice: Title: "Carefree", source: freemusicarchi...

Комментарии • 56

  • @mechtutorcom
    @mechtutorcom  Месяц назад

    Download your FREE "MATLAB Cheat Sheet" from here: mechtutor.thinkific.com/products/digital_downloads/matlab-cheatsheet

  • @rgyu7978
    @rgyu7978 2 года назад +1

    oh dr mard i have taken a course with you in benghazie uinversity really you was the best who explain the machanisam i am happy to meet you again my name is radi i already working in one of libyan largest oil company i remmber i take A dgree in your course i am happy so much to find you here again ^^

  • @bera1339
    @bera1339 11 месяцев назад +1

    u r such a nice teacher keep going on

  • @sadiqueansari447
    @sadiqueansari447 3 года назад +1

    To the point explanation ... Thanks

  • @skr746
    @skr746 3 года назад +1

    Thank you so much

  • @rylannaicker1345
    @rylannaicker1345 3 года назад

    great video, very helpful explanation

  • @aldisa98
    @aldisa98 4 года назад

    Really good video! You have explained it beautifully. Thanks~

  • @abdulrahmanalhalawi760
    @abdulrahmanalhalawi760 3 года назад +1

    Thank you so much 🥺

  • @salimasalima8125
    @salimasalima8125 4 года назад +1

    Sir, i have worked only in Matlab and i really enjoyed your videos.
    I want to buy your course on udemy. However, i see that the latter uses only python.
    Iam wondering if i will buy the lesson, i can easily implement methods on matlab since the original course is in python?
    Are python and matlab same in coding?

  • @zhiwarsami5737
    @zhiwarsami5737 6 лет назад

    Thanks very much. You are really the best

  • @sihemprincess1955
    @sihemprincess1955 6 лет назад

    Thanks ever so much for your help.
    Please, i have questions about the MATLAB code used for the bisection method:
    1- Does the keyword "return" mean skipping from if and whole program (for example from line 6 to the end of the program)? and what is the difference between it and break?
    2- You did not use nested if because there is no relation between conditions?
    3- Could we start with this condition y(x2)*y(xh) instead of y(x1)*y(xh)?

    • @mechtutorcom
      @mechtutorcom  6 лет назад +2

      Hello. Very good questions.
      1- the keyword 'return' exits the execution of the current script and returns to the MATLAB command prompt. The 'break' statement is used to quit the current loop (while or for loops). Note that the statements 'exit' and 'quit' terminate the whole MATLAB program itself.
      2- Nested if-conditions are usually used when there are more than one level of conditions. For example { if x >= 0 ... if sqrt(x)

    • @sihemprincess1955
      @sihemprincess1955 6 лет назад

      thank you. Could you make a video about nested if? And explain it with details.

  • @Salehalanazi-7
    @Salehalanazi-7 5 лет назад

    You're a genius

  • @irladoralizamantillanunez5
    @irladoralizamantillanunez5 4 года назад

    Thanks you very much for your help

  • @souadmassi7683
    @souadmassi7683 4 года назад +1

    Thank you sir for this nice and interesting video.
    What if we do not want to use the handle @ in the way of writing y at the biginning. How will be the code?

    • @mechtutorcom
      @mechtutorcom  4 года назад +1

      There are two alternative ways to define a function in MATLAB, as I know. First, you can use inline() definition method, which is an obsolete method and not recommended to be used anymore. The second method, is to use the function definition method which needs to be coded a new .m file. This method is recommended if you do not define the function in body of your bisection code, or if you have a function has multiple lines of code.

    • @souadmassi7683
      @souadmassi7683 4 года назад

      @@mechtutorcom Thank you sir and really i want to know more about programming loops and different tips about it. It will be wonderful if you make videos about it.

  • @MOHAMMADSABRAJHOSSEN
    @MOHAMMADSABRAJHOSSEN 3 года назад +2

    Why abs(y(x1)) rather it wil be abs(y(x2))

    • @mechtutorcom
      @mechtutorcom  3 года назад +2

      As iterations proceed, the values of x1 and x2 get closer and closer to the root, and consequently y(x1) and y(2) get closer and closer to zero. It is difficult to predict which one will be within the given tolerance (1.0E-6) first: abs(y(x1)) or abs(y(x2)). For that reason, either one will work well -- no difference.
      Also, you can modify the code to use xh, so each new value can be tested before assigning it to x1 or x2. You need to move the test condition up just under the bisection line:
      .
      .
      xh = (x1+x2)/2; %bisection
      if abs(y(xh)) < 1.0E-6
      break
      if y(x1) *y(xh) < 0
      .
      .
      This may be better.

  • @karimelectronics6760
    @karimelectronics6760 6 лет назад +1

    Thank you for this helpful video.
    What if we want to use while loop. What will be the condition inside the while?

    • @mechtutorcom
      @mechtutorcom  6 лет назад +1

      karim electronics When while loop is used, the whole if condition {if abs(y(x1)) < 1.0E-6 ... break ... end} should removed and the condition of the while loop is written as following
      while abs(y(x1)) >= 1.0E-6
      ...
      end
      The other statements remain unchanged. If the number of bisections at the solution is required, a counter {i=i+1} can be added inside the loop.

    • @karimelectronics6760
      @karimelectronics6760 6 лет назад

      Is it correct instead of
      while abs(y(x1)) >= 1.0E-6
      ...
      end
      we can put
      while abs(y(x2)) >= 1.0E-6
      ...
      end
      ?

    • @mechtutorcom
      @mechtutorcom  6 лет назад +1

      Yes, it is correct. Because during bisections both x1 and x2 approach to the root from both sides and y(x1) and y(x2) accordingly approach to zero.

    • @karimelectronics6760
      @karimelectronics6760 6 лет назад

      Thank you sir

  • @Scho229
    @Scho229 4 года назад

    How can I see the result of each Iteration step and not only my final result? Great Video!

  • @maqsoodalam
    @maqsoodalam 5 лет назад +1

    Best

  • @noorulhasheem3398
    @noorulhasheem3398 3 года назад

    Hi I was required to use whle loop instead how would I go about it and also i tried doing it much shorter and I think i am required to find the bisection not the root exactly.

  • @busraturk1233
    @busraturk1233 Год назад

    i wrote the same codes but my progman is error that y=0(x). it says this is an invalid expression. what should i do?

  • @asege
    @asege Год назад

    Please I want to know which version of MATLAB you used

    • @mechtutorcom
      @mechtutorcom  Год назад

      Actually, in MATLAB/Octave videos, I used Octave. It has very similar syntax to MATLAB. You should take into consideration that these videos were recorded back in 2017 and 2018, so there must be many changes in the languages ever since.

  • @prateekmalwe2305
    @prateekmalwe2305 5 лет назад

    please have a MATLAB program for Euler's modified method for the same numerical

  • @aljae.intheoceans
    @aljae.intheoceans 2 года назад

    THANK YOU SO MUCH SIR THIS VIDEO HAS MADE IT LESS COMPLICATED. ouh uh BUT i cannot download the code file ahuhu i think the link is broken

  • @overdoscream
    @overdoscream 4 года назад

    So helpful , thank you so much for the video
    but i didn't understand when you write in matlab " if abs(y(x1)) < 1.0E-6 " .
    what does it mean please ?

    • @mechtutorcom
      @mechtutorcom  4 года назад +4

      Good question Mouad. The root of an equation is defined as the point of intersection between the curve of the equation and the x-axis, and at that point y(x) = 0. According to this definition, a root is approached if y(x1) is zero or very close to zero. In numerical methods, it is almost impossible to get the exact zero, so it is assumed that the root is found if y(x1) is inside the range of -1.0E-6 to +1.0E-6. This range can be easily be tested by using the absolute value function and the positive part of the range in the condition statement: if abs(y(x1)) < 1.0E-6.
      I hope I could answer your question.

  • @peshawasalih8784
    @peshawasalih8784 5 лет назад +1

    Thanks for the useful video, I have a question.
    I try this method to get the value of x from the equation:
    (x*pi/180)+cotd(x)-C
    while (C) is an array vector, the method works but it only calculates x only and only for the last element value
    of the vector (C).
    Is there a possible solution?

  • @kotoamatsukami7782
    @kotoamatsukami7782 4 года назад

    Thank you sir, very helpful
    I wanna ask a question to you, whats the meaning of number of bisection?

    • @mechtutorcom
      @mechtutorcom  4 года назад +3

      The total number of bisections means how many times the intervals need to be divided until the root is approached.
      I hope I could answer your question.
      Thanks for your comment.

    • @kotoamatsukami7782
      @kotoamatsukami7782 4 года назад

      @@mechtutorcom ouh i see, thank you very much, sir

  • @brucewernick6542
    @brucewernick6542 2 года назад

    What is the Python editor you are using?

    • @mechtutorcom
      @mechtutorcom  2 года назад +1

      It's IDLE, downloaded for free from python.org

  • @eneserden8299
    @eneserden8299 4 года назад

    thank you sir, but have can we get the steps of bisection? I want to see processes too.

    • @mechtutorcom
      @mechtutorcom  4 года назад

      Thank you for the comment. I couldn't understand what you mean by processes, but the steps can be written as following;
      1- Input two values of x that embrace the interval where the root is expected
      2- Calculate corresponding values for y
      3- Check for the sign difference between y-values
      4- In case of same signs, stop
      5- Calculate the value of x in the half of the interval
      6- Check for the sign difference between the y-values first half interval
      7- In case of opposite signs, calculate the value of x in the half of the interval
      8- In case of similar signs, take the x-values bounding the second half
      9- If the values of y approaches zero, print the x-value and stop
      10- Else repeat steps 6 to 10

  • @arhammalik310
    @arhammalik310 6 лет назад

    Can you make a functions of this? I mean that program allows to enter any equation to solve the root?

  • @josepferrer81kg39
    @josepferrer81kg39 4 года назад +2

    i love you

  • @Surya-uv3bz
    @Surya-uv3bz 2 года назад

    Why you used abs (y(X2)) instead of x2-x0 or x1-x2 for error

    • @Surya-uv3bz
      @Surya-uv3bz 2 года назад

      Please reply if anyone knows

  • @RizuwanaParween-m9x
    @RizuwanaParween-m9x 10 месяцев назад

    Where is the use of i

  • @alexanderlindemann1937
    @alexanderlindemann1937 3 года назад

    Get an error for fprintf

  • @collinsmutuma3885
    @collinsmutuma3885 5 лет назад +1

    You honestly are charging a student 29$ for the Code

    • @nabDoesYoutube
      @nabDoesYoutube 4 года назад +1

      or you just copy it by typing it out, its not hard...