Adding an extra point in a grid in finite element code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Saarthak Gupta
am 29 Nov. 2023
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:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!