how to solve this question using two loops?

2 件のコメント

James Tursa
James Tursa 2015 年 4 月 17 日
編集済み: James Tursa 2015 年 4 月 17 日
Once you have the formula you can calculate this with MATLAB functions. Other than that, what is the MATLAB related question here? I assume this is homework, so we would appreciate you showing some effort first.
John D'Errico
John D'Errico 2015 年 4 月 17 日
編集済み: John D'Errico 2015 年 4 月 17 日
Anyway, why do you need MATLAB to do this at all? Seems like pencil and paper are sufficient to write down the general formula. Oh, yeah, its homework. So start writing code. Or, think about the problem, and then write down the solution as a simple enough formula.
I'd suggest first thinking along the lines of symmetry. Is there some symmetry in this problem? What does that mean in terms of the solution? (Often symmetries in mathematics are useful tools to reduce the complexity of a problem.)
As well, look at small problems, then see if there is a pattern you might recognize.

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

 採用された回答

James Tursa
James Tursa 2015 年 4 月 17 日
編集済み: James Tursa 2015 年 4 月 17 日

0 投票

Big Hint:
Suppose the grid is M x N. You've got (M+N) total moves to make, with M of them being "down" and N of them being "right". Suppose you number the moves 1,2,...,(M+N). How many ways can you pick M numbers from this ordered list of (M+N) numbers for the ordering of the "down" moves (the remaining numbers will be the "right" moves)? Figure that out, and what MATLAB function can be used to calculate it, and you will have your answer.

1 件のコメント

John D'Errico
John D'Errico 2015 年 4 月 17 日
Interestingly, my solution is completely different, arising from a different approach, but with a simple identity can be shown to be identical.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 4 月 18 日

0 投票

Steve Eddins gives an extensive discussion on this in his 5-blog series on this: http://blogs.mathworks.com/steve/2011/11/01/exploring-shortest-paths-part-1/

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

タグ

質問済み:

2015 年 4 月 17 日

回答済み:

2015 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by