Question

I'm writing a code for adaptive finite element method in 1d. I have an interval let say [0,1] and in first iteration I have a mesh, x=0:.25:1 and in second iteration I would like to divide the second and last segment in 3 and 5 segments. So the updated vector, x has 11 nodes. This process will be repeated over and over with different segments. I am really confused how can I update the vector x?

Was it helpful?

Solution

Let's say your vector x has n elements. And you want to update the i-th segment and divide it into k parts. then:

x = [x(1:i-1), x(i):((x(i+1) - x(i))/k):x(i+1), x(i+2:n)];

OTHER TIPS

One way to do this is:

x = 0:0.25:1;
xrefined3 = [x(1):0.25/3:x(2) x(2:end-1) x(end-1):0.25/3:1];
xrefined5 = [x(1):0.25/5:x(2) x(2:end-1) x(end-1):0.25/5:1];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top