1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Newtons Method In Matlab

  1. Oct 7, 2012 #1
    I'm tasked currently with creating a matlab function to run newton's method. From there I need to use this function to solve for the constants of a catenary which pass through (+-50, 100). I used wolfram alpha to find the proper constant as 107.432 so I would know if I was on the right track or not.

    The equations I'm given:
    [tex]x=t[/tex]
    [tex]y=c*cosh(\frac{t}{c})-c[/tex]

    I computed the derivative to be
    [tex]\frac{dy}{dt}=sinh(\frac{t}{c})[/tex]

    This is the code I have thus far:
    Code (Text):

    function result = newton(x, epsilon, imax)
    %NEWTON Performs newton's method like a boss
    %   Detailed explanation goes here

    %c=107.43201882596103613561001;
    i = 1;
    fprintf('Newtons Method Iterations: %i\n', imax);

    while(i<=imax)
        root = (x - (csc349_asgn3_fy(x,c)/csc349_asgn3_fpy(x,c)));
        fprintf('Iteration: %i, Root: %2.10f\n', i, root);
       
        if(abs(1-(x/root))<epsilon)
           
            result = root;
           
            return
        end
       
        i=i+1;
        x=root;
    end

    fprintf('FAILED TO CONVERGE IN GIVEN ITERATION LIMIT\n');

    end
     
    The functions csc349_asgn3_fy(x,c), and csc349_asgn3_fpy(x,c) respectively represent the function y and the derivative.

    Code (Text):

    function result = csc349_asgn3_fy(t,c)
    %CSC349_ASGN3_FY function to be fed into newtons method
    %   Detailed explanation goes here

    result = c*cosh(t/c)-c;

    end
     
    Code (Text):

    function result = csc349_asgn3_fpy(x,c)
    %CSC349_ASGN3_FPY derivative of function to be fed into newtons method
    %   Detailed explanation goes here

    result=sinh(x/c);

    end
     
    Now, I have no idea what to do. I know that I should start with x0 being 50, and the assignment specifies 20 iterations. I've tried a few things, but all the results I have thus far are incorrect.

    From what I see, the constant c just needs to be fiddled with until the function for the y coordinate is equal to 100. I'm not sure how to go about implementing this though.
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Newtons Method In Matlab
  1. Matlab Newton's Method (Replies: 1)

Loading...