Matlab help. Using Newton Raphson

In summary: You might want to consider defining p explicitly as part of the functions, and then passing x/theta as an argument.
  • #1
thekkid33
4
0

Homework Statement


Two forces P and Q are applied at the end of a screw eye in order to remove the post.


Homework Equations


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


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
 
Physics news on Phys.org
  • #2
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
yes i am
 
  • #4
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.
 
  • #5
!



Hello,

Thank you for reaching out for help with your Matlab homework. It seems like you have a good understanding of the problem and have made a good attempt at solving it. I will provide some guidance on how to approach this problem in Matlab.

First, you are correct in recognizing that you will need to create an M-file to solve this problem. This M-file will contain your equations and the Newton-Raphson algorithm.

To start, you will need to define your function f(θ) and its derivative f'(θ) in the M-file. You can use the anonymous function syntax in Matlab to define these functions:

f = @(theta) sin(theta)*sqrt(3)*P + P*cos(theta) - 800;
fd = @(theta) P*(2*cos(30)*cos(theta) - sin(theta));

Next, you will need to define the initial guess for θ, the number of iterations (n), and the desired accuracy (eps). You can also define the range of P values and the step size (ΔP) as variables.

x0 = 400; % initial guess for theta
n = 16; % number of iterations
eps = 0.001; % desired accuracy
P = 400:25:800; % range of P values
dP = 25; % step size for P

Now you can use a for loop to iterate through each value of P and use the Newton-Raphson algorithm to solve for θ. Within the for loop, you will also need to use equation (1) to solve for Q.

for i = 1:length(P) % loop through each value of P
x = x0; % set initial guess for theta
for j = 1:n % iterate through the Newton-Raphson algorithm
x = x - f(x)/fd(x); % update theta using Newton-Raphson
end
theta(i) = x; % save the value of theta for this P
Q(i) = 2*P(i)*sin(x); % solve for Q using equation (1)
end

Finally, you can plot P vs Q using the values of theta that were calculated for each P.

plot(P, Q); % plot P vs Q
xlabel('P'); % label the x-axis
ylabel('Q'); % label the y-axis
title('P vs Q for Different Values of Theta');
 

1. What is Matlab?

Matlab is a high-level programming language and interactive environment commonly used by scientists and engineers for data analysis, visualization, and computational tasks.

2. What is the Newton Raphson method?

The Newton Raphson method, also known as the Newton's method, is an iterative method for finding the roots of a function. It uses the derivative of the function to approximate the root and converges quickly for most functions.

3. How can I use the Newton Raphson method in Matlab?

To use the Newton Raphson method in Matlab, you can create a function that represents the equation you want to solve and use the built-in function "fzero" to find the root. Alternatively, you can write your own code to implement the method step-by-step.

4. What are the advantages of using the Newton Raphson method in Matlab?

The Newton Raphson method is a powerful and efficient way to find the roots of a function. It has a fast convergence rate and can handle complex functions. In Matlab, it is easy to implement and can be used for both symbolic and numerical calculations.

5. What are some common errors that may occur when using the Newton Raphson method in Matlab?

Some common errors that may occur when using the Newton Raphson method in Matlab include: division by zero, non-convergence of the method, and incorrect input of the equation or initial guess. It is important to check for these errors and make necessary adjustments to ensure accurate results.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
815
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
753
  • Engineering and Comp Sci Homework Help
Replies
1
Views
701
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Introductory Physics Homework Help
2
Replies
38
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top