How to find the intersections of two functions in MATLAB? -


lets say, have function 'x' , function '2sin(x)'

how output intersects, i.e. roots in matlab? can plot 2 functions , find them way surely there must exist absolute way of doing this.

if have 2 analytical (by mean symbolic) functions, can define difference , use fzero find zero, i.e. root:

f = @(x) x;        %defines function f(x) g = @(x) 2*sin(x); %defines function g(x)  %solve f==g xroot = fzero(@(x)f(x)-g(x),0.5); %starts search x==0.5 

for tricky functions might have set starting point, , find 1 solution if there multiple ones.

the constructs seen above @(x) something-with-x called anonymous functions, , can extended multivariate cases well, @(x,y) 3*x.*y+c assuming c variable has been assigned value earlier.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -