# Adding an extra point in a grid in finite element code

조회 수: 1 (최근 30일)
Hussein Kokash 2022년 2월 7일
답변: Saarthak Gupta 2023년 11월 29일
Dears,
I am using this code that solves the 1D BVP -au'' + bu' + cu = f in (x0, x1) at x0 to x1.
I am diving the intervals to n=16.
I need to add an extra node (point) between the last two nodes so it will be between 15/16 and 16/16.
Any Idea how to do so?
Here is the part of the code concerning the intervals and the matrix forming:
n = 16;
x = linspace(leftbdr.x, rightbdr.x, n+1);
% assemble matrix A
A = sparse(n+1,n+1);
for i=1:n % on each sub-interval [x(i), x(i+1)]
localmat = assembleLocalMatrix(x(i),x(i+1),coefficients);
A(i:i+1,i:i+1) = A(i:i+1,i:i+1) + localmat;
end
% assemble right-hand side vector rhs = (f,v)
rhs = zeros(n+1,1);
for i=1:n % on each sub-interval [x(i), x(i+1)]
localrhs = assembleLocalRhs(x(i),x(i+1),f);
rhs(i:i+1) = rhs(i:i+1) + localrhs;
end
Thanks

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

### 답변 (1개)

Saarthak Gupta 2023년 11월 29일
Hi Hussein,
I understand you are trying to insert an additional point between the last two points of a linearly spaced interval of 16 points.
You can achieve the desired result using simple array indexing and concatenation.
Refer to the following code:
% Original interval
n = 16;
x = linspace(leftbdr.x, rightbdr.x, n+1);
% Suppose you wish to insert a point p (assigned an arbitrary value for the
% sake of this example) between the last two points of the interval
p = 10;
x2 = [x(1:end-1) p x(end)];
It inserts ‘p’ between the last two points of the interval, and the length of the resulting vector is one greater than the original.
Please refer to the following MATLAB documentation for further reference:

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

### 카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by