フィルターのクリア

Adding an extra point in a grid in finite element code

3 ビュー (過去 30 日間)
Hussein Kokash
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
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 Center および File ExchangeLoops 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