How to enter this program?
4 ビュー (過去 30 日間)
古いコメントを表示
Hello, I have tried unsuccessfully for a couple hours to enter a program that loops until a number that is even, divisible by both 13 and 16, and whose square root is greater than 120 is found. I have reached a wall, so I have come to ask for help. Would using a while statement be the first step? Please don't solve this problem, I only ask for help getting it going. Yes, this is basic stuff, but I still have little understanding on it.
0 件のコメント
採用された回答
Roger Stafford
2014 年 10 月 25 日
You need to translate each of those conditions into a matlab logical proposition. For example if n is an integer you are investigating, try dividing it by 13, then comparing the 'round' of the quotient with the original quotient to see if it is still an integer after the division. And yes, the 'while' function is the right thing to use here. Keep it looping until all the conditions turn out to be true for the same integer, for which you can make great use of the "&" operation.
5 件のコメント
その他の回答 (2 件)
Rick Rosson
2014 年 10 月 25 日
編集済み: Rick Rosson
2014 年 10 月 25 日
Here is a faster and simpler approach:
a = 0;
while a < 120^2
a = a + 13*16;
end
per isakson
2014 年 10 月 26 日
編集済み: per isakson
2014 年 10 月 26 日
Try
>> factor( cssm )
ans =
2 2 2 2 2 5 7 13
where cssm is
function ix = cssm()
% chose a start value, which is larger than 120^2 and divisible by 16
ix = 120*120+16;
while ne( mod(ix,13), 0 )
ix = ix + 16;
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!