# Solving systems of equations graphically and finding where they cross.

4 visualizaciones (últimos 30 días)
Sumer el 21 de Oct. de 2023
Comentada: Sumer el 21 de Oct. de 2023
I've got the following non-linear equation that I need to solve: F(x) = 2x - 3sin(x) +5. I know how to graph it and my code is below. However, I don't know how to find the intersection points. Am I supposed to use fplot or smth?
How can I find the exact coordinates for where y and F(x) intersect?
Could I have found the x-intercepts of F(x) without considering y?
%define x, y and F(x)
x = linspace(-20,20,2000);
F = 2*x-3*sin(x)+5;
y = zeros(size(x));
% plot the graphs on the same graph
hold on
plot(x,F)
plot(x,y)
% make the graph lookd neater
grid on
xlabel('x')
ylabel('F(x)')
title(' plot of F(x)')
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Matt J el 21 de Oct. de 2023
Editada: Matt J el 21 de Oct. de 2023
x_intersect=fzero(@(x) 2*x-3*sin(x)+5 ,[-20,+20])
x_intersect = -2.8832
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Sumer el 21 de Oct. de 2023
Thanks very much! This is extremely practical.

Iniciar sesión para comentar.

### Más respuestas (2)

Fabio Freschi el 21 de Oct. de 2023
Editada: Fabio Freschi el 21 de Oct. de 2023
@Matt J solution is the cleanest. I have understood you want to find the graphical intersection. If you want to do it yourself you can calculate the line between the two points before and after the crossing and find the zero of the line.
clear variables, close all
%define x, y and F(x)
x = linspace(-20,20,2000);
F = @(x)2*x-3*sin(x)+5; % <- anonymous function
y = zeros(size(x));
% plot the graphs on the same graph
hold on
plot(x,F(x))
plot(x,y)
% make the graph lookd neater
grid on
xlabel('x')
ylabel('F(x)')
title(' plot of F(x)')
% find where you are crossing the 0
idx = find(diff(sign(F(x))));
% find crossing of linear interpolation of these two points
x0 = x(idx)+F(x(idx))*(x(idx+1)-x(idx))/(F(x(idx+1))-F(x(idx)))
x0 = -2.8997
plot(x0,F(x0),'o');
• You should also check if by chance, one of your x is a solution, that is F(x) = 0.
• If you have more intersections, idx is a vector and you can loop over the vector length to find all intersections
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Sumer el 21 de Oct. de 2023
Thanks for the solution!

Iniciar sesión para comentar.

Walter Roberson el 21 de Oct. de 2023
How can I find the exact coordinates for where y and F(x) intersect?
You cannot. There is no known closed-form expression for the coordinates. The best you can do is get a numeric approximation. You could use fzero or fsolve for that, or vpasolve
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Sumer el 21 de Oct. de 2023
Thanks very much!

Iniciar sesión para comentar.

### Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by