- #1
Lancelot59
- 646
- 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:
The functions csc349_asgn3_fy(x,c), and csc349_asgn3_fpy(x,c) respectively represent the function y and the derivative.
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.
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:
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:
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:
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.