Finding and displaying the intersection of two functions

4 views (last 30 days)
I want my program to find the intersection between two functions. If there are multiple solutions for this, I want it to display multiple solutions.
My code is currently like this:
function polarisatiecurve
P = 600;
I = 0:1:30;
U1 = P./I;
U2 = 20*I.^2 - 2*I.^3;
plot(I,U1,I,U2);
axis ([0 30 0 200])
xlabel('Stroom (A)')
ylabel('Spanning (V)')
title('Polarisatiecurve')
grid on
end
I need to find the intersection of U2 and U1. I already tried this:
C = intersect(U1,U2)
But that gave me the following:
C =
Empty matrix: 1-by-0
How do I fix this?

Accepted Answer

Mischa Kim
Mischa Kim on 16 Jan 2014
Edited: Mischa Kim on 16 Jan 2014
Use
P = 600;
fzero(@(I) 20*I.^2 - 2*I.^3 - P./I, 10)
ans =
9.6680
fzero(@(I) 20*I.^2 - 2*I.^3 - P./I, 3)
ans =
3.6069
and simply add two more data points to the plot
  4 Comments
Wouter
Wouter on 16 Jan 2014
I see. But can it also display the Y values? Or do I have to take the inverse of the function and then make it do the same but with the inverse formula?
Mischa Kim
Mischa Kim on 16 Jan 2014
Forgot about the plotting part. Here you go:
P = 600;
my_fun = @(I) P./I;
my_fun_diff = @(I) 20*I.^2 - 2*I.^3 - P./I;
x1 = fzero(my_fun_diff, 3);
y1 = feval(my_fun, x1);

Sign in to comment.

More Answers (1)

Hasan Ballouk
Hasan Ballouk on 17 Dec 2021
Edited: Hasan Ballouk on 28 Jan 2022
hi every body,
I have two functions here f(x1) and f(x2).
Can I add constrains in Matlab, so that I let them meet in (0,0)?
best regards
Ballouk

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!