How can i reverse my plot?

6 visualizaciones (últimos 30 días)
Sedat Peker
Sedat Peker el 25 de Jun. de 2020
Editada: Adam Danz el 26 de Jun. de 2020
Hello everyone, i am trying to code stream function in Matlab. i am done with alghoritmic part but having a problem with my contour plot. If you check the result for "u_new" matrix, it starts from 100 at the bottom and go to 0 when we move to upper parts. When i plot it with counter function, plot starts 100 value from top completely symmetric to what i want to plot? what is my mistake here? And also i want to limit x axis with 6 and y axis with 4 on my plot. Right now the interval is huge. Can you help me please. Here is my code;
clear all;
% for the task in CFD tutorial Video 12 - Matlab version of given C code
length_x = 6.0; % Length of x axis of confined space.
length_y = 4.0;
X = 31; % Number of points will be generated on X axis
Y = 21;
dx = length_x / (X-1);
dy = length_y / (Y-1);
criterion = 1e-8;
u_new=zeros(Y,X); %generating arrays to store the potential value (psi) of each point
u_old=zeros(Y,X);
% Defining coefficients of the discretized equation
a_p = 2 * (1 / dx^2 + 1 / dy^2);
a_e = 1 / (dx^2);
a_w = 1 / (dx^2);
a_n = 1 / (dy^2);
a_s = 1 / (dy^2);
% Defining Dirichlet Boundary Conditions
u_new(21 , 1/dx+2 : 1 : 6/dx+1) = 100;
u_old = u_new;
error = 1;
while error > criterion
error=0;
% Defining Jacobi Iteration Method
for i=2 : 1 : Y-1
for j=2 : 1 : X-1
u_new(i,j) = (1 / a_p) * (a_e * u_old(i+1,j) + a_w * u_old(i-1,j) + a_n * u_old(i,j+1) + a_s * u_old(i,j-1));
end
end
% Applying given Neumann Boundary Conditions
for i=1 : 1 : Y
u_new(i,X) = u_new(i,X-1);
end
error = 0 %Now we add the error term so in each general loop we will calculate the error and stop iteration when the amount go lower than the error we want to see
for i=1 : 1 : Y
for j=1 : 1 : X
error = error + (u_new(i,j) - u_old(i,j))^2;
end
end
error = sqrt(error / ((X-2) * (Y-2)));
u_old = u_new;
end
contour(u_new,'ShowText','on')

Respuesta aceptada

Adam Danz
Adam Danz el 25 de Jun. de 2020
Editada: Adam Danz el 26 de Jun. de 2020
I'm guessing you want to flip the y-axes.
set(gca,'YDir','reverse')

Más respuestas (0)

Categorías

Más información sobre Vector Fields en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by