Matrix Population from formula

I have a i x j matrix that follows the formula....
[(u(i-1,j)-2*u(i,j)+u(i+1,j)/(.2^2)]-[(u(i,j)-u(i,j-1))/(.2)]=0
How do I populate a 6x6 matrix using this as the formula
I have the following boundary conditions: if i=1 u=0, if i=6 u=100, if j=1 u=0, if j=6 u=0.

댓글 수: 3

Torsten
Torsten 2024년 11월 20일
편집: Torsten 2024년 11월 20일
If i goes from 1 to 6 and j goes from 1 to 6, the matrix will be 36 x 36 because you have 36 values u(i,j) to solve for.
The problem results in a linear system of equations of the form
A*U = b
with A being 36x36 and b being 36x1 that can be solved "in one go" using U = A\b.
You have to decide the order in which the U-vector is arranged (either you cycle through the i-j-grid row- or columnwise).
Since your equations show that you only have convection, but no diffusion in j-direction, you cannot impose a boundary condition for j = 6. The values for U at j = 6 emerge from the interior of the domain.
William Rose
William Rose 2024년 11월 20일
The equation ofr u(i,j) looks like a second derivative with respect to i, minus a first derivative with respect to j, where the delta value equals 0.2 for the i and j directions.
Start with matrix u having the boundary conditons along the boundaries, and zero everywhere else. Or let the initial value be a linear gradienmt from 0 to 100 in the u direction. Then apply the equaitons for u(ij) inthe interior, once. See what you have. Then do it again, and again, and again. See if it is evloving twoard a constant value, or getting more oscillatory, or something else.
By the way, your boundary contions are problematic: Does u(6,6)=0 or 100?
Alexander
Alexander 2024년 11월 20일
편집: Alexander 2024년 11월 20일
That is what this is. What would a code for this look like? u(6,6)= 100

댓글을 달려면 로그인하십시오.

답변 (1개)

Saurabh
Saurabh 2024년 11월 20일
편집: Saurabh 2024년 11월 21일

0 개 추천

I understand that you want to populate a 6x6 matrix using the given formula. In MATLAB, you can use the 'zeros' function to create a matrix of any size with initial values set to zero. You can then iterate over the matrix and apply the formula to each element.
And then explicitly assign the boundary condition later.
For more information on the 'zeros' function referred to the following documentation:
I hope this helps.

댓글 수: 3

Alexander
Alexander 2024년 11월 20일
How do I apply that formual to each element? How do I make matlab recognize that i= rows and j= columns
John D'Errico
John D'Errico 2024년 11월 20일
편집: John D'Errico 2024년 11월 20일
Just use a loop! Surely you can use a nested loops, over i and j? TRY IT! You will get better and more help if you make an effort.
Walter Roberson
Walter Roberson 2024년 11월 20일
It seems to me that you would likely have to loop several times to get the matrix to settle down.
On the other hand, it looks like a matrix that is all zero satisfies the conditions.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2024년 11월 20일

편집:

2024년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by