필터 지우기
필터 지우기

Write a function so that, when given a natural number N, the function returns the value max  n ∈ N : 12 + 22 + · · · + n 2 ≤ N

조회 수: 1 (최근 30일)
Write a function so that, when given a natural number N, the function returns the value max n ∈ N : 12 + 22 + · · · + n 2 ≤ N
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 1월 22일
So the question is about finding the largest n such that the sum of squares of 1 to n is less than or equal to the original number? Hmmm, plausibly.
It would have been easy enough for the poster to have clarified that when asked a year ago.

댓글을 달려면 로그인하십시오.

답변 (4개)

Andrei Bobrov
Andrei Bobrov 2016년 1월 17일
your_function = @(n,m,N)sum((n+m):n:N);
use
>> n = 10;
m = 2;
N = 90;
>> your_function(n,m,N)
ans =
376
>>

Torsten
Torsten 2016년 1월 18일
n=floor((-7+sqrt(20*N+49))/10);
Best wishes
Torsten.

Rusty
Rusty 2016년 1월 17일
function [ p ] = rusty( N)
a(1)=12;
i=1;
while sum(a(:))<=N
a(i+1)=a(i)+10;
i=i+1;
end
if sum(a(:))>N
a(end)=[];
end
if isempty(a)
disp('N is less than 12');
return
else
p=(a(end)-2)/10
end
  댓글 수: 3
Rusty
Rusty 2016년 1월 18일
you just go and save this file. now open the command window and write : rusty(36), if N=36, and you will get the answer

댓글을 달려면 로그인하십시오.


Márcio
Márcio 2022년 10월 20일
Write a function that for a given natural number nn returns the matrix which has 2 rows, in its first row every entry is 1, while in its second row there are the numbers n,n−1,…,1n,n−1,…,1 (in this order).
  댓글 수: 1
Torsten
Torsten 2022년 10월 20일
N = 3624;
v = N:-1:1;
A = [ones(1,2*N);[v,v]]
A = 2×7248
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3624 3623 3622 3621 3620 3619 3618 3617 3616 3615 3614 3613 3612 3611 3610 3609 3608 3607 3606 3605 3604 3603 3602 3601 3600 3599 3598 3597 3596 3595

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by