Did I do something wrong solving this PDE in MATLAB?

106 Views Asked by At

I have the following PDE problem on a practice exam:

enter image description here

I have completed the problem using MATLAB to the best of my ability. Here is the code I used

M = [0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0];

h = 0.1;
k = 0.1;

%bottom row initial condition
for i=1:11
   x = (i-1) * 0.1;
   M(11,i) =  (0.1)*(x^2);
end

%right column initial condition
for i=1:10
   realI = 11-i;
   t = (11-realI) * 0.1;
   M(realI,11) = (0.1) * (1+t)^2;   
end

%n+1 row using u_t boundry condition
for i=2:10
   x = (i-1) * 0.1;
   left = M(11,i-1);
   right = M(11,i+1);
   M(10,i) = (left + right + 0.04*x)/2;   
end

%calculate the remaining n+1 row point (leftmost point)
M(10,1) = 0.1/5; %(1/5)t

%Now, just use the scheme to solve the rest of the points, and the t/5
%to calculate the edges
for n=1:9
   real_n = 10-n; %count from 9 to 1 rather than 1 to 9
   for m=2:10       
       M(real_n,m) = M(real_n + 1, m-1) + M(real_n + 1, m+1) - M(real_n + 2, m);
   end
   %leftmost point
   t = (n+1)/10;
   M(real_n, 1) = t/5; 
end

M
surf(M);

The problem is that I have no way of knowing that I am correct as my professor does not release solutions for practice exams.

My specific problem is I am not confident that I got the left column correct, but I'm also hoping to get feedback on my answer as a whole. Can someone either replicate the problem or check over my code?

Here are my results with the code that I posted:

enter image description here

Did I do the left column correctly? Does my algorithm look correctly matched to the equations outlined in the problem? Are there any ways I can improve the code that I wrote if it actually is correct? MATLAB is a bit of a second language to me. (har har)

1

There are 1 best solutions below

1
On BEST ANSWER

You missed that the left boundary condition is a derivative $u_x(0,t)=t/5$. Transcribing task descriptions has its uses.

You can compare your solution to the exact solution $u(x,t)=(x+t)^2/10$. If the method is correctly second order, the numerical value should coincide with the actual values.