How do I nondimensionalized plot axis?
Show older comments
clc
clear all
%set number of nodes
Nx=51; % x nodes
Ny=51; % y nodes
%define constants
a=1; %normalized x length
b=1; %normalized y length
H=1; %H is a constant
%grid spacing
dx=a/(Nx-1); %grid spacing in x direction
dy=b/(Ny-1); %grid spacing in y direction
%build grid
x=dx*(0:(Nx-1)); %points along x
y=dy*(0:(Ny-1)); %points along y
[X,Y]=meshgrid(x,y);
%initialize theta
theta=zeros(Nx,Ny); %initialize theta to zero
%Left Boundary Condition
theta(1,:)=y.*(1-y);
%begin iteration (jacobi)
for n=1:100000 %number of iterations
I=2:(Nx-1);
J=2:(Ny-1);
%update the interior points
theta(I,J)=(dy^2*(theta(I+1,J)+theta(I-1,J))+...
(a*dx/b)^2*(theta(I,J+1)+theta(I,J-1)))/(2*dy^2+2*(a*dx/b)^2);
%update top boundary
theta(I,Ny)=(4*theta(I,Ny-1)-theta(I,Ny-2))/(3+2*dy*H);
%update right boundary
theta(Nx,J)=(4*theta(Nx-1,J)-theta(Nx-2,J))/3;
%corner points (average above and below)
theta(1,1)=(theta(1,2)+theta(2,1))/2;
theta(1,Ny)=(theta(1,Ny-1)+theta(2,Ny))/2;
theta(Nx,Ny)=(theta(Nx-1,Ny)+theta(Nx,Ny-1))/2;
theta(Nx,1)=(theta(Nx-1,1)+theta(Nx,2))/2;
end
flipud(theta')%this is important because this reverses the rows and cols to match x and y
%plots
figure
plot(theta(:,(Ny+1)/2));
title('theta(X,0.5) vs X')
xlabel('X')
ylabel('theta(0.5,Y)')
figure
plot(theta((Nx+1)/2,:));
title('theta(0.5,Y) vs Y')
xlabel('Y')
ylabel('theta(0.5,Y)')
figure
contourf(X,Y, theta');
title('theta(X,Y)')
xlabel('X')
ylabel('Y')
Outputs 3 figures. I want the horizontal axis on the line graphs to read from 0 to 1. Can anyone please help? Thanks
Accepted Answer
More Answers (1)
Rick S
on 9 Mar 2018
Categories
Find more on Mathematics 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!