フィルターのクリア

How to identify points on a graph of multiple functions

5 ビュー (過去 30 日間)
Samuel Eronmwon
Samuel Eronmwon 2023 年 2 月 6 日
コメント済み: Samuel Eronmwon 2023 年 2 月 9 日
I wish to identify the point where y=0 for four functions on the same figure with a dot. I understand that interp1 can be used do this but I plotted my functions using "fplot" and it seems that Interp1 doesn't work with fplot. So how do I do this?
Here is my code;
n1= exp(1);
n2= 2.95;
n3= 3.05;
n4= pi;
figure;
f1 = @(x) n1-tan((x-(pi/4))/5);
fplot(f1,[0,8])
hold on
f2 = @(x) n2-tan((x-(pi/4))/5);
fplot(f2,[0,8])
hold on
f3 = @(x) n3-tan((x-(pi/4))/5);
fplot(f3,[0,8])
hold on
f4 = @(x) n4-tan((x-(pi/4))/5);
fplot(f4,[0,8])
grid on
title('Plot of Functions')
xlabel('Y values')
ylabel('X values')
legend('n=e','n=2.95','n=3.05','n=pi')
Using Snipping tool, this is what I want to produce
Those coloured dots such that when hovered over it displays the values.

採用された回答

Tushar Behera
Tushar Behera 2023 年 2 月 6 日
編集済み: Tushar Behera 2023 年 2 月 6 日
Hi Samuel,
I believe you want to identify spots where y=0 on your plot.
To find the x values where y=0 for each function, you can use the fsolve function. fsolve finds the roots of a function, so you can use it to find the x values where each function crosses the y=0 line. Here's an example of how you can find the roots and plot them on the same figure:
n1= exp(1);
n2= 2.95;
n3= 3.05;
n4= pi;
figure;
f1 = @(x) n1-tan((x-(pi/4))/5);
fplot(f1,[0,8])
hold on
f2 = @(x) n2-tan((x-(pi/4))/5);
fplot(f2,[0,8])
hold on
f3 = @(x) n3-tan((x-(pi/4))/5);
fplot(f3,[0,8])
hold on
f4 = @(x) n4-tan((x-(pi/4))/5);
fplot(f4,[0,8])
grid on
% Find the roots using fsolve
x1 = fsolve(f1,pi/4);
x2 = fsolve(f2,pi/4);
x3 = fsolve(f3,pi/4);
x4 = fsolve(f4,pi/4);
% Plot the roots on the same figure
scatter(x1, 0, 'ro');
scatter(x2, 0, 'ro');
scatter(x3, 0, 'ro');
scatter(x4, 0, 'ro');
title('Plot of Functions with Roots')
xlabel('Y values')
ylabel('X values')
legend('n=e','n=2.95','n=3.05','n=pi')
I hope this is what you were looking for.
Regards,
Tushar
  1 件のコメント
Samuel Eronmwon
Samuel Eronmwon 2023 年 2 月 9 日
Thank you. This answer's my question very well. I'm grateful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by