How do I plot multiple intersections between two functions?
Mostra commenti meno recenti
I have been tasked with plotting two functions as well as marking where the two intersect. I also have to use a for or while loop to automatically find all of the intersections in the given domain and print the results of those intersections.
if true
% code
%%Find all of the intersections of two functions in the domain of x
% Variable 3 ≤ x ≤ 8
% Functions
F1 = @(x) 90.*exp(-x) - 1;
F2 = @(x) sin(2.*pi.*x);
fplot(F1,[3,8]);
grid on;
hold on;
fplot(F2,[3,8]);
for k = 1:7
int = fzero(@(x) F1(x)-F2(x),k); % The x-coord
plot(int,F1(int),'*k'); % The coordinates.
fprintf('Intersection %0.0f is at x = %0.4f\n', k, int);
end
end
My for loop is not working the way I need it to, so any help would be excellent. Here are a couple hints I have been given:
Hint 1: How do you make an anonymous function that takes one variable (x) and returns zero when the two functions intersect?
Hint 2: You need to call fzero a bunch of times with a reasonable set of guesses, enough to make sure that you actually get all of the intersections. Each time you calculate a new intersection, compare it to ALL of the intersections that you have already calculated. If the difference between the new intersection and any of the old ones is very small (<0.00006), do not add it to your list and just move on to calculating the next one. Don’t forget to check that the intersection is in the given domain.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!