-
-
Save unreadable/9db39711fd9b9c1d0d39843ffac2f372 to your computer and use it in GitHub Desktop.
Matlab hm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) | |
len = size(M)(1) | |
M(1) + M(len) + M(len*len - (len + 1)) + M(len*len) | |
2) | |
sum(sum(M)) | |
3) | |
function (m,n) | |
eye(m,n) | |
end | |
4) | |
function get_sum(M) | |
[m, n] = size(M) | |
v = zeros(1, m) | |
for i=1:m*n | |
if i < m*(n-1) | |
v(floor(i/n) + 1) += M(i) | |
else | |
v(m) += M(i) | |
end | |
end | |
end | |
5) | |
function M = swap(M, o, n) | |
[m, n] = size(M) | |
c = 0 | |
for i=1:(m*n) | |
if M(i) == o | |
M(i) == n | |
c += 1 | |
end | |
end | |
end | |
6) | |
function p = get_pi(n=100) | |
p = 0 | |
for k=0:n | |
p += ((-3)**(-k))/(2*k+1) | |
end | |
p = sqrt(12) * p | |
end | |
7) | |
function odd, even = pariry(mat) | |
odd = [] | |
even = [] | |
[m, n] = size(mat) | |
for i=1:(m*n) | |
if mat(i) % 2 == 0 | |
even = [even, mat(i)] | |
else | |
odd = [odd, mat(i)] | |
end | |
end | |
end | |
8) | |
function res = calc(n, t) | |
res = 0 | |
for k=1:n | |
res += (sin((2*k - 1) * 5))/(2*k - 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment