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!