# Matlab help. Using Newton Raphson

1. Sep 18, 2013

### thekkid33

1. The problem statement, all variables and given/known data
Two forces P and Q are applied at the end of a screw eye in order to remove the post.

2. Relevant equations
The two equations that were found are
1.) Q*sin(30)-P*sin(θ)=0
2.) Q*cos(30)+P*cos(θ)-800=0

3. The attempt at a solution
I combined the 2 equations by first solving (1) in terms of Q=2*P*sin(θ)
then plugged into equation (2) (2*P*sin(θ))*cos(30)+P*cos(θ)-800=0
then got f(θ)=sin(θ)*(√3)*P+P*cos(θ)-800=0
wanted f(θ)=0 as final equation
f'(θ)=P*(2*cos(30)*cos(θ)-sin(θ) (i do not think this is correct though)

Then I have to write a newton raphson for θ for a given P and solve for θ.
use P=400 to 800 with ΔP=25.
compute θ for each P
once θ is found for each P use equation (1) to find Q
Now plot P and Q for each θ.

I am very new to Matlab. (only introduced to it 2 weeks ago) and i am not to sure how to start. This is what i came up with but it is very confusing to me.

x0=400; n=16; eps=0.001; fun=@(tha) 2*p*sin(tha)*cos(30)+p*cos(tha)-800=0; fund=@(x) p*(2*cos(30)*cos(x)-sin(x); nr=(x0,n,eps,fun,fund)
function nr(x0, n, eps, f, fd)
func=f(x0); dfunc=fd(x0);
for i=400:n
x=x0-func/dfunc;
fprintf ('%4d %8.4f %8.4f %8.4f\n',i,func, dfunc, x)
func=f(x); dfunc=fd(x);
if abs(x-x0) < eps , break, end
x0=x;
end

**i know there needs to be an M-File for this set up but i am not sure how to do that either.

Thanks in advance for the help

2. Sep 18, 2013

### voko

I know nothing about about Matlab, but I know that this problem can be solved with a bit of simple trigonometry.

Are you supposed to use Newston-Raphson and Matlab to solve this?

3. Sep 18, 2013

### thekkid33

yes i am

4. Sep 18, 2013

### voko

Well, in that case I should say that $f(\theta)$ and $f'(\theta)$ seem correct (except you need to slap a closing bracket onto the latter).

What does not look right, though, is that the functions you define in the program have p in them, yet p is not defined anywhere, nor is it passed as a parameter to them. I think there is some confusion between p and the functions' x/theta argument.