Please help explain it

5 visualizaciones (últimos 30 días)
Jennifer
Jennifer el 7 de Sept. de 2025
Respondida: Sam Chak el 8 de Sept. de 2025
Problems 1 & 2) Let x and y be related by: y = x + cos(x)
1) Use graphical methods solve for x when y = -0.5 y = +0.5
2) Find the solutions to problem #1 using Newton's method
Problems 3 & 4) Let x and y be related by
y = cos(2x)
y = (x − 2)(x + 1)
3) Find all solutions in the range of (-4 < x < 4) using graphical methods. (Plot both functions on the same graph. The solution is when the two functions intersect.)
4) Find the solutions to problem #3 using Newton's method.
  3 comentarios
Jennifer
Jennifer el 7 de Sept. de 2025
it didn't help thank you though
Umar
Umar el 8 de Sept. de 2025

Hi @Jennifer,

Thank you for sharing your exercises. I would also like to acknowledge the contributions of @Torsten, whose insights help frame both the theoretical and practical approach.

  • @Torsten suggested a useful roadmap: first visualize intersections graphically, then refine roots numerically using Newton’s method.

I’d like to guide you conceptually so you can use your own reasoning to implement it. Here’s pseudocode that outlines the steps:

 *Pseudocode*

For each problem:

1. Define the functions - Problem 1 & 2: f(x) = x + cos(x) - Problem 3 & 4: f1(x) = cos(2x), f2(x) = (x-2)*(x+1)

2. Graphical exploration a. Choose a suitable x-range b. Plot the functions on the same axes c. Look for approximate x-values where the curves intersect - These will serve as initial guesses for Newton’s method

3. Newton’s method (root-finding) a. Define the difference function: diff(x) = f1(x) - f2(x) (or f(x) - target y) b. Compute derivative diff'(x) c. For each initial guess x0: i. x_new = x_old - diff(x_old)/diff'(x_old) ii. Repeat until convergence (change is smaller than tolerance) iii. Store the root

4. Verification a. Plug roots back into original functions b. Check that f1(root) ≈ f2(root) (or f(root) ≈ target y)

5. Optional: Plot the roots on the graphs for confirmation

How this helps you think independently

  • The pseudocode breaks the problem into conceptual steps: visualize, guess, iterate, and verify.
  • You will learn why Newton’s method works and how plotting informs your initial guesses.
  • By following this roadmap, you will be able to implement the solution in MATLAB.

Hope this helps.

Iniciar sesión para comentar.

Respuestas (2)

Torsten
Torsten el 7 de Sept. de 2025
Editada: Torsten el 8 de Sept. de 2025
1) asks you to plot y1(x) = x + cos(x), y2(x) = -0.5 and y3(x) = 0.5 and see where y1 and y2 resp. y1 and y3 intersect.
2) asks you to do the same with Newton's method, i.e. you are to determine the root(s) of y1(x) - y2(x) = x + cos(x) + 0.5 in the first case and y1(x) - y3(x) = x + cos(x) - 0.5 in the second case.
3) asks you to plot y1(x) = cos(2*x) and y2(x) = (x − 2)(x + 1) in the range -4 < x < 4 and see from the graphs where y1 and y2 intersect.
4) asks you to do the same with Newton's method, i.e. you are to determine the root(s) of y1(x) - y2(x) = cos(2*x) - (x − 2)(x + 1) in the interval -4 < x < 4.
At least 1) and 3) should be no problem, I think.

Sam Chak
Sam Chak el 8 de Sept. de 2025
I believe you have learned how to plot graphs from your Professor. So, I will proceed directly to demonstrating how to use MATLAB's built-in fsolve() function, which uses Newton's method, to find the intersections of two nonlinear equations.
To be honest, the instructions are somewhat misleading. The graphical method alone typically cannot provide the exact numerical solutions for the intersection of two nonlinear graphs, as it only indicates where the curves meet. I attempted to solve it graphically without using specific MATLAB functions such as sign() and diff(), to find() the zero-crossing locations, but I was unsuccessful.
figure(Name="Problems 3 & 4");
% Newton's method
fun = @(x) y1(x) - y2(x);
x0 = [-1, 2]; % initial guess
for i = 1:2 % since there are 2 intersections, we repeat the procedure 2 times.
xsol(i) = fsolve(fun, x0(i))
end
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
xsol = -0.9132
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
xsol = 1×2
-0.9132 1.6202
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure(Name="Solutions 3 & 4");

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by