Am I using poicalc correctly?
조회 수: 2 (최근 30일)
이전 댓글 표시
The solution returned using poicalc is too large by almost 1 order or magnitude. I expect the maximum z value of the surface to be 1, but instead I am getting 7.9976 (almost 8). I will post exactly what I did below.
I used the periodic, 2D function
And I set a = 1 to make things simpler
syms u(x,y,a)
u(x,y,a) = 2^(4*a) * x^a * (1-x)^a * y^a * (1-y)^a;
u(x,y,a) = subs(u(x,y,a),a,1); %sub in a = 1 into equation
u(x,y,a)
%% Cartesian Space
% x = [0,.1,.2,...,X=1], y = [0,.1,.2,...,Y]
X = 1; Y = 1;
Lx = 99; Ly = 99;
dx = X/Lx; dy = Y/Ly;
x_arr = linspace(0,X,Lx+1);
y_arr = transpose(linspace(0,Y,Ly+1));
x_arr
y_arr
u_func(x,y,a) = u(x,y,a); % This is a term that we will be using to sub into u(x,y,a)
u(x,y,a) = subs(u(x,y,a),x,x_arr(1,:)); % sub in x
u(x,y,a) = subs(u(x,y,a),y,y_arr(:,1)); % sub in y. I noticed that I could sub in a transposed array instead of using a meshgrid
u_xy = double(u(x,y,a)) % We need to convert this to a double for plotting purposes later on
%% Now we plot the solution
figure(1)
contour3(x_arr,y_arr,u_xy);
surface(x_arr,y_arr,u_xy);
title('u(x,y)');
xlabel('x = linspace(0,1,11)');ylabel('y = linspace(0,1,11)');
Then we set up the Poisson equation that we are trying to solve for in order to get back to the solution graphed above.
f_func = diff(u_func,x,2) + diff(u_func,y,2);
A = subs(f_func,'x',x_arr);
B = subs(A,'y', y_arr);
f = double(B);
size(f)
Now that we have f(x,y)< we will use poicalc on f(x,y) to get back to u(x,y).
%% Use poicalc function
% Now we run the poicalc function which takes in parameters (f,h1,h2,n1,n2)
h1 = dx; % gridspace_x
h2 = dy; % gridspace_y
n1 = 100; %number of points in x. supposed to be 100 but n1*n2 has to equal the number of rows in f
n2 = 1; % number of points in y. Supposed to be 100.
% n2 seems to dictate the number of local maxima and minima or
% slopes
% if I put n2 = 2, I get 2 slopes, and if n1 = n2 = 10, I get 10
% slopes.
u_calc = poicalc(f,h1,h2,n1,n2);
%% Now we plot it to examine how well it matches our first plot
figure(2)
contour3(y_arr,x_arr,abs(u_calc));
surface(y_arr,x_arr,abs(u_calc));
title('u(x,y) computed using poicalc function');
xlabel('x');ylabel('y');
max(max(abs(u_xy)))
max(max(abs(u_calc)))
Personally I don't have too much issue with the shape, my biggest issue is with the magnitude being off. The maximum value for u_xy in the first plot is very nearly 1, and the max for the solution obtained for u(x,y) here is very nearly 8. What exactly am I doing wrong with the poicalc function that is resulting in this disparity in magnitude?
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!