Array operations
古いコメントを表示
How can I solve this problem using MATLAB? The array n is all integers from 1 to 110. The array y is defined by: y= n^(1/2) if n is divisible by 3, 5, or 7 y= 0 otherwise Find the value of the sum of the elements of y.
4 件のコメント
James Tursa
2012 年 3 月 22 日
What code have you written so far? Which parts are you stuck on?
Aldin
2012 年 3 月 22 日
I can't understand is n these numbers:
ans =
Columns 1 through 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Columns 19 through 36
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
Columns 37 through 54
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
Columns 55 through 72
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
Columns 73 through 90
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
Columns 91 through 108
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
Columns 109 through 110
109 110
or random generated
James Tursa
2012 年 3 月 22 日
Yes, n is those numbers.
Andrei Bobrov
2012 年 3 月 23 日
out = sum(sqrt(num(all(bsxfun(@rem,num.',[3 5 7]),2))))
採用された回答
その他の回答 (1 件)
Jan
2012 年 3 月 22 日
Start with:
n = 1:110;
Now remember that ^(1/2) is the squareroot.
How can you check, if the numbers in a vector can be divided by 3, 5, or 7? Look e.g. in the help for rem:
doc rem
Another idea:
x = 1:3:20
...
カテゴリ
ヘルプ センター および 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!