How can I efficiently mesh 2D lines in MATLAB
조회 수: 2 (최근 30일)
이전 댓글 표시
I have created a 2D mesher (for lack of a better word?). Its useage is as follows:
xmin = -pi/2;
xmax = +pi/2;
numx = 8; % desired number of points for output distribution
funx = @(x) sin(x); % example function to mesh
xq = varspace(funx,xmin,xmax,numx); % optimally sampled domain
xq =
-1.5708 -1.2809 -0.9157 -0.5130 0.5028 0.9363 1.2368 1.5708
plot(xq,funx(xq,'rs-')) % plot of sin(x) with variable spacing
I like this example because it illustrates how sin(x) is very linear at x=0 so there is no need to sample this region as much as near the endpoints in the domain.
For the time being, I've accomplished this method of variably sampling x by generating a relative spacing array and tweaking with :
dx = fminsearch(@(m) err(m),ones(1,numx)); diff(xq) == dx
so as to minimize the error between the original @funx and an interpolated interp1(xq,funx(xq),...).
In 2D, this procedure doesn't take forever but I'm wondering if there are resources to accomplishing this task in a more deterministic way. Computing f''(x) and sampling based on this proportion seems like a reasonable solution but I'm betting this question has been answered before, I just can't find the correct phrase to describe it.
댓글 수: 3
RobF
2018년 1월 23일
Hello Alexander,
could you please be a little more specific on what you want to achieve? Additionally, I cannot find the command "varspace" in the documentation - is this a special function?
Jan
2018년 1월 23일
@RobF: "varspace" must be downloaded from the FileExchange: https://www.mathworks.com/matlabcentral/fileexchange/65808-varspace-funx-xmin-xmax-numx-varargin-
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Direct Search에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!