# Newtons Method In Matlab

1. Oct 7, 2012

### Lancelot59

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:
$$x=t$$
$$y=c*cosh(\frac{t}{c})-c$$

I computed the derivative to be
$$\frac{dy}{dt}=sinh(\frac{t}{c})$$

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.