필터 지우기
필터 지우기

How to specify a variable (using linspace) like this?

조회 수: 5 (최근 30일)
Shashank
Shashank 2012년 10월 8일
Distance between first and second point and the distance between second last and last point is 0.5h. All other distances between the neighboring points is h. How to create a grid of say N points that do not include the first and the last point in the grid?

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 10월 8일
편집: Andrei Bobrov 2012년 10월 8일
afirst = 2;
h = .5;
N = 5;
out = afirst + cumsum([0, .5*h,ones(1,N-1)*h,.5*h])
or
out = [afirst,linspace(afirst + .5*h,afirst + .5*h + (N-1)*h,N),afirst + N*h];
or
a = [2 6];
N = 5;
L = linspace(a(1),a(2),N+1)
L(2:end) = L(2:end)-diff(a)/N*.5
out = [L,a(end)];
  댓글 수: 2
Taha
Taha 2012년 10월 8일
He has asked "do not include the first and the last point". I think your solutions include the first and last points.
Shashank
Shashank 2012년 10월 8일
Thanks Andrei. You seem to have given me a lot of options. I think the second one looks more cogent.

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


Taha
Taha 2012년 10월 8일
편집: Taha 2012년 10월 8일
N = 5;
h = (last - first)/N;
grid = linspace(first+h/2, last-h/2, N);
  댓글 수: 2
Shashank
Shashank 2012년 10월 8일
So if I need to call a matrix, say A = f(1) + f(3), how should I do it using your method? And should I specify the values of "first" and "last" as the end points of my domain?
Taha
Taha 2012년 10월 8일
편집: Taha 2012년 10월 8일
The above piece of code needs 'N', 'last', and 'first' as input parameters. Also, I didn't get what you mean by 'calling a matrix'.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by