how do you implement an iteration for a stream function?

Hello, so I'm trying to create a stream function contour plot. I created my mesh and have implemented my boundary conditions that I calculated by hand. I'm getting my functions from my fluids book, and it has psi as psi = psi(i,j)+ .25*( psi(i,j+1) + psi(i,j-1) + psi(i+1,j) + psi(i-1,j)). So I run this over the i and j components that I want to calculate, and I am not getting the values I want because it is not iterating and I don't know how to do that. For reference I am using an excel version of this where I calculated in node using that equation mentioned earlier. I have a snapshot of my excel sheet and the calculation I used.excel example of stream function.JPG
and this the code I currently have for calculating the stream function after the boundary conditions
for i = 2:Nx
for j = 2:Ny
psi(i,j) = psi(i,j)+ .25*( psi(i,j+1) + psi(i,j-1) + psi(i+1,j) + psi(i-1,j));
end
end
Thank for any help you guys can provide

4 Comments

What did you initialize psi to?
Notice by the way that psi(i, j-1) and psi(i-1,j) are referring to values that you calculated on this run, not to just initially stored values. For example when you are working on 3 3 then it accesses the 3 2 value that you just stored on the immediately prior j iteration and the 2 3 value you calculated on the previous i iteration. Order of calculation is important: you only iterate most as you head down and right. The bottom right corner will have been affected by all of the other iterations.
The psi that I'm calculating, I don't have it initialized so I guess it's just zero. And I see what you mean by order of calculations. So what I want to do is to set a loop so that after the first time it runs, it goes back to make sure that all the points I calculated follow the condition I set. And right now it can't do that because they're all zero so they are much smaller than they should be at the end
What boundary conditions are you setting? If you are not initializing psi row 1 or column 1 at least then all of your calculation would be on zeros.
It's exactly the same as the Excel model above. I am now thinking I might off for part of it. But for the left side it's 0:1:10 but what I have coded in is psi(1,j) = psi(1,j-1) + 10*dy. bottom to the top. The bottom and right side are both zero. The top is 10 all along but I think it should be like the left side but psi(i,10) = psi(i-1) + 10*dx.

Sign in to comment.

Answers (0)

Products

Release

R2019a

Asked:

on 3 May 2019

Community Treasure Hunt

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

Start Hunting!