How to plot loglog graph of error vs number of elements in matlab for boundary value problem for dirichlet condition (or any)?

7 views (last 30 days)
Hello, I have a bar which has been dicretized into n number of elements. I have a different mesh for the actual solution of the pde which has been plotted more finely in the figure below. Now I want to plot the error vs number of elements in a log plot and want to prove that the slope will be 2. How can I do that? The picture attched is the plot of both exact and finite element which is dicretized into 4 elements.

Answers (1)

Anmol Dhiman
Anmol Dhiman on 31 Jan 2020
Hi Biswabhanu,
You can use semiology to plot the error vs number of elements.
I have tried to reproduce the plot along with the error plot.
x = 0:0.01:0.25;
y = 0.25:0.01:0.5;
z = 0.5:0.01:0.75;
w = 0.75:0.01:1;
x_all = 0:0.01:1;
parabola = @(x)(1-10*(x.^2)+10*x);
value_x0 = parabola(0);
value_x = parabola(0.25);
value_y = parabola(0.5);
value_z = parabola(0.75);
value_w = parabola(1);
line1 = linspace(value_x0, value_x, size(x,2));
line2 = linspace(value_x, value_y, size(y,2));
line3 = linspace(value_y, value_z, size(z,2));
line4 = linspace(value_z, value_w, size(w,2));
line = [line1,line2(2:end-1),line3,line4(2:end)];
%plotting the figure that is mentioned in the question
%plot(x_all,parabola(x_all),x_all,line);
error = parabola(x_all) - line;
semilogy(x_all,error);
Hope it helps

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!