Intersection of two lines

How can I get the coordinates of the intersections of two linear diagrams with a given expression or equation?

for example: L1 = sin (2x), L2 = Ln (x); or something else.

+3
source share
5 answers

Surprisingly, no one has yet suggested using a function designed for this in Matlab. Use fzero here. In any case, Fzero is a better choice than fsolve, which requires an optimization toolbar. And, yes, you could do this using the Newton method or even bisecting or secant method. But reinventing the wheel is not something that needs to be done in general. Use the functionality that already exists when it is.

The problem is to find the point where

sin(2*x) == log(x)

log (x) . , , .

fun = @(x) sin(2*x) - log(x);

, . ezplot .

ezplot(fun)

, 1 2.

fzero(fun,2)
ans =
       1.3994
+6

matlab, fsolve(@(x)sin(2*x)-log(x),1), 1.3994 (1 ). - log(1.3994) = 0.3361.

fsolve, , , sin(2*x) == log(x), sin(2*x) - log(x) == 0 (log - matlab).

, , , L1 = @(x)sin(2*x) L2 = @(x)log(x) ( L1.m L2.m) fsolve(@(x)L1(x)-L2(x),1).

+4

, L1 (x) = L2 (x). , L1 L2 (, ...), , , Netwon. () f (x) = L1 (X) - L2 (X).

+2

: , , .

, bisection .

.

+2

As a general non-analytic solution, when you have two curves described by two sets of points, File Exchange has an excellent feed - Fast and Reliable intersection curves .

0
source

Source: https://habr.com/ru/post/1732486/


All Articles