How to solve equation by iteration
Show older comments
Hello,
Im trying to solve this equaiton below (for Psi(i,j)) but im not sure what im missing. I should be getting a 220x40 matrix with various values for Psi but im not sure how to go about doing this.
clear
clc
Vinf = 1;
c = 1;
L = 11*c;
H = 4*c;
N = 220;
deltax = L/N;
M = 40;
deltay = H/M;
epsilon = 10^(-6);
yi=linspace(0,L,M);
xi=linspace(0,H,N);
z=zeros(M,N);
for i = 1:N-1
for j = 1:M-1
x(i,j) = i*deltax;
y(i,j) = j*deltay;
Psi(i,j) = ((deltay^2)/(2*((deltax^2)+(deltay^2))))*(Psi(i+1,j)+Psi(i-1,j))+((deltax^2)/(2*((deltax^2)+(deltay^2))))*(Psi(i,j+1)+Psi(i,j-1));
end
end
%boundary conditions
Psi(0,j) = Vinf*deltay*j;
Psi(i,M+1) = Vinf*H;
Psi(N,j) = Psi(N-1,j);
Psi(i,1) = 0;
1 Comment
Your equations can't be solved directly for Psi because Psi appears on both sides of the equation.
But your equations define a linear system for Psi.
Determine A such that your system is of the form
A*Psi = b
and solve for Psi as
Psi = A\b.
Or if you are told to use Jacobi iteration, apply a scheme like
Psi_new(i,j) = function(Psi_old(i,j),Psi_old(i+1,j),Psi_old(i-1,j),Psi_old(i,j+1),Psi_old(i,j+1))
Thus you will not only need one matrix Psi, but two matrices Psi_old and Psi_new.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!