⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 discpoints.m

📁 GDDEMO runs a little demonstration of gradient descent in Matlab. Launch Matlab, and type gddemo to
💻 M
字号:
function [x,y] = discpoints(cx, cy, r, n)
% DISCPOINTS   Random points within a disc.
%    [X,Y] = DISCPOINTS(CX, CY, R, N) returns N randomly generated points 
%    with coordinates (X,Y) contained in a disc of radius R centered at 
%    (CX,CY) of radius R.  

% generate 2N points in a square whose center is the center of the circle
% and whose side is twice the radius
x = randpts(cx, r, 2*n);
y = randpts(cy, r, 2*n);

% take points from the disc centered inside the square
d = sqrt((x-cx).^2 + (y-cy).^2);
x = x(find(d<r));
y = y(find(d<r));

% keep N points from the circle
x = x(1:n);
y = y(1:n);

% local function generating N random points in line segment whose midpoint
% is C and whose length is 2N
function x = randpts(c, r, n)
x = c + rand(1,n) * r*2 - r;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -