Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d = 70;
- M = d-1;
- N = d-1;
- %solve Laplace equation
- % nabla^2 u(x,y) = 0
- % Specification of rectangular area
- x0 = 0; xf = 4; % minimal and maximal value of x-coordinate
- Mx = d; % number of intervals in x direction
- y0 = 0; yf = 4; % minimal and maximal value of y-coordinate
- My = d; % number of intervals in y direction
- bx0 = inline('exp(y) - cos(y)','y'); % Boundary condition for left edge
- bxf = inline('exp(y)*cos(4) - exp(4)*cos(y)','y'); % Boundary condition for right edge
- by0 = inline('cos(x) - exp(x)','x'); % Boundary condition for bottom edge
- byf = inline('exp(4)*cos(x) - exp(x)*cos(4)','x'); % Boundary condition for top edge
- % a vector for defining rectangular area
- D = [x0 xf y0 yf];
- %Parameters for Jacobi Method
- MaxIter = 1000; % Maximal number of iteration
- tol = 1e-3; % tolerance of Jacobi method
- % Solving Laplace equation via function sollap
- [Ua,x,y] = sollap(bx0,bxf,by0,byf,D,Mx,My,tol,MaxIter);
- Un = zeros(d+1);
- for i = 1:length(x)
- for j = 1:length(y)
- Un(i,j) = -((exp(y(j)) * cos(x(i))) - (exp(x(i)) * cos(y(j))));
- end
- end
- Ud = Un - Ua;
- Ud2 = Ud.^2;
- totals = zeros(1, length(Ud2));
- for i = 1:length(Ud2)
- totals(i) = sum(Ud2(i,:));
- end
- USum = sum(totals);
- error = sqrt((1/(M*N)) * USum);
- In new script thing....
- d=[5 10 15 20 25 30 35 40 45 50 55 60 65 70]
- Error= [0.2459297 0.057170249 0.019832251 0.008179454 0.016384573 0.028631307 0.041942391 0.05724528 0.073729247 0.091975748 0.111647881 0.176497771 0.294126947 0.440691868]
- In new script....
- zz=zeros(1,70);
- for i=1:1:70
- zz(i) = ((3.424e-07*i^4) -(5.145e-05*i^3) + (0.002808*i^2) -(0.06226*i) + 0.4775)
- end
- figure(1)
- plot(zz,':b')
- hold on
- box on
- plot(d,Error, 'or')
- xlabel('Grid Size, d')
- ylabel('Error')
- title('Error between the Analytical and Numerical solution')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement