Finding the shortest path

2 ビュー (過去 30 日間)
Axelina Lindgren
Axelina Lindgren 2021 年 4 月 16 日
コメント済み: Walter Roberson 2021 年 4 月 17 日
How do you code so that you mark the shortest path in this problem? The problem is to find the shortest optical path between two points in different materials. The rays diverge exactly halfway between the two points. I understand how to find the minimum value of the function but not how to mark (or replot in another colour) the ray that is the shortest. dopt is the function that calculate the total optical path from the first point to the second. Grateful for help!
  2 件のコメント
Andrew Newell
Andrew Newell 2021 年 4 月 16 日
Just to be clear - in this example, are equal to ?
Walter Roberson
Walter Roberson 2021 年 4 月 17 日
If you were using a graph() object to do the plotting, you could use highlight()

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

回答 (1 件)

Clayton Gotberg
Clayton Gotberg 2021 年 4 月 16 日
After you have found the minimum value of the function, you can simply replot over the same line in a different color. The most recently plotted object should cover any previously plotted objects by default.
If you were to save the value of the length on each iteration (for example, dtot(i+4)=dopt(i)), you could find the index of the minimum and replot that line just as you did in the for loop.
for i = -3:1:3
dtot(i+4)=dopt(i);
line(i)% plot lines
hold on
end
[~,min_index] = min(dtot);
line(min_index,'Color','blue')% plot lines
If you need the shortest possible line and not just the shortest line of the ones you plotted, you can perform the minimization and then plot the line using that value of .

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by