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 件のコメント

Walter Roberson
Walter Roberson 2019 年 5 月 3 日
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.
Rashid Coulibaly
Rashid Coulibaly 2019 年 5 月 3 日
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
Walter Roberson
Walter Roberson 2019 年 5 月 3 日
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.
Rashid Coulibaly
Rashid Coulibaly 2019 年 5 月 3 日
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.

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2019a

質問済み:

2019 年 5 月 3 日

コメント済み:

2019 年 5 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by