MATLAB Code of Newton-Raphson method for root finding

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ธ.ค. 2024

ความคิดเห็น • 18

  • @stergiostziahanas6532
    @stergiostziahanas6532 หลายเดือนก่อน

    Made some modifications, hope this helps..
    format short
    syms x
    % Define the function and its derivative
    f = @(x) x*log10(x) - 1.2;
    df = matlabFunction(diff(f(x), x)); % Convert symbolic derivative to function
    % Initial guess and parameters
    x0 = 1.5;
    n = 6;
    iter = 1;
    err = abs(f(x0));
    epsilon = 5 * 10^(-n - 1);
    itermax = 70;
    % Array to store iteration data
    HG = [];
    % Check if the derivative at initial guess is non-zero
    if abs(df(x0)) < 10^(-9)
    disp('Wrong choice of initial Guess');
    else
    % Newton-Raphson iteration
    while (iter epsilon)
    x1 = x0 - f(x0) / df(x0);
    err = abs(f(x1)); % Update error with new x1 value
    HG = [HG; iter, x0, f(x0), err]; % Append current iteration data
    iter = iter + 1;
    x0 = x1; % Update x0 for next iteration
    end
    end
    % Display results
    disp('=====');
    disp('Output Table with Iteration-wise Results');
    % Convert results to table with column names
    Result = array2table(HG, 'VariableNames', {'Iteration', 'x', 'f(x)', 'Error'});
    disp(Result);
    % Round solution to n decimal places
    x0 = round(x0, n);
    fprintf('Converged solution after %d iterations
    ', iter - 1);
    fprintf('Root is %2.*f
    ', n, x0);

  • @jaffarlone8378
    @jaffarlone8378 3 ปีที่แล้ว +4

    Dear Sir, Your lectures are really very helpful. Please upload the videos on the MATLAB implementation of Descent Methods.

  • @jacobjacob3687
    @jacobjacob3687 ปีที่แล้ว

    Appreciate much Dr Harish ,,,, God bless u ,, you have been help me so much ,,,, 🙏🙏👍👍

  • @yaoxie3531
    @yaoxie3531 2 ปีที่แล้ว

    An advice to improve the algorithm. The IF condition should be "abs(dfx(x0))

  • @zainabakram1543
    @zainabakram1543 ปีที่แล้ว

    sir i need the code for an ODE by using newton raphson method. can you give me?

  • @PradeepKumar-eh1jr
    @PradeepKumar-eh1jr 3 ปีที่แล้ว +5

    This code is not running in my system.

  • @hutheifa4880
    @hutheifa4880 2 ปีที่แล้ว

    Thank you dr. .... I have a question; does the value of roots changes if we use different value for the initial point?

    • @DrHarishGarg
      @DrHarishGarg  2 ปีที่แล้ว +1

      No

    • @hutheifa4880
      @hutheifa4880 2 ปีที่แล้ว

      @@DrHarishGarg I have found a matlab code that finds the roots of two functions of two variables by using Newton Method. I know that for quadratic equation the roots should be two values; one +ve and one -ve of the same root value. This can be noticed with using different initial values. Thats why I raised my question earlier. However, how could we let the matlab code shows the both values without plotting. Hope my question is clear.

    • @DrHarishGarg
      @DrHarishGarg  2 ปีที่แล้ว

      That's called as multiple roots of f(x)

  • @sumitsana6170
    @sumitsana6170 2 ปีที่แล้ว

    How can I write this code in "c"?

  • @kashafiftikhar1314
    @kashafiftikhar1314 2 ปีที่แล้ว

    Please sir code de dein Ricci tensor ka lea

  • @McPlaySpot
    @McPlaySpot 3 ปีที่แล้ว +2

    Thank you Dr.

    • @DrHarishGarg
      @DrHarishGarg  3 ปีที่แล้ว +1

      My pleasure dear

    • @vivekmehta6833
      @vivekmehta6833 3 ปีที่แล้ว

      @@DrHarishGarg Hey! I'm a Freelancer and I do have pirated versions of the softwares. And I was planning to make videos on mechanical softwares like MATLAB, Solidworks, AutoCAD, etc on TH-cam. Like how to design a particular thing or how to write a code for a particular problem. All these softwares cost 1000s of dollars a year for individual/commercial license which obviously I can't afford. If you could help me out with a few questions, I would be really grateful of you!!!
      1) When I apply for monetization, will I be asked whether I have commerical licenses of the aforementioned softwares by TH-cam?
      2) If TH-cam doesn't ask for commercial licenses and after that my content is monetized, at what point can I expect these companies to send me a notice regarding the licenses? At 10k subscribers? 50k? 100k?
      3) How much money do TH-camrs with 10-50k subscribers from 3rd world countries like India get monthly? Any idea?
      4) Is it really worth it? I mean I do have the skills and knowledge but I honestly don't think I would be able to afford these softwares until and unless I start earning 500-1000$ per month via TH-cam.

  • @hometutionacademybygowhers9594
    @hometutionacademybygowhers9594 หลายเดือนก่อน

    Best

  • @nikolai7548
    @nikolai7548 2 ปีที่แล้ว

    Thanks sir.