How can i put this recurring calculation into a for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
so far my code is as shown below
clc
clear all
k = 143; % thermal conductivity of copper, W/(m-K)
rho = 2.8; % density of copper, kg/m^3
specificHeat = 795; % specific heat of copper, J/(kg-K)
x=input('Enter the dimension of the x axis of the plate in meters: ');
y=input('Enter the dimension of the y axid of the plate in Meters: ');
f0=input('Enter a value for the Fourier Number: ');
while f0 <= 0 f0>0.25
f0=input('Enter a value for the Fourier Number: ');
end
h=input('Enter the grid spacing: ');
while h<0
h=input('Enter the grid spacing: ');
end
a=(x/h)
xx=a+1
b=(x/h)
yy=b+1
m = zeros(xx,yy) % grid spacing of the plate
m(1,:)=50 % initial boundary conditions at top of plate
m(yy,:)=10 % initial boundary condition at bottom of platec
n=40/b
I am trying to put in boundary conditions along the left and right hand side i have worked out that the equation is
m(yy-c,1)=10+n
m(yy-c,1)=10+2*n
m(yy-c,1)=10+3*n
how can i put this into a for loop where the boundary conditions will be put in for any size matrix?
댓글 수: 2
Tamir Suliman
2016년 12월 2일
you will have explain what you trying to do how is h < 0 and f0 less than 0 and greater than 0.25
If some one answers your questions please click approve answer to give them credit for the effort they took to answer your questions.
답변 (1개)
Sid Jhaveri
2016년 12월 6일
I am assuming that according to the user given input, you have to calculate the number of iterations(loops) your for loop need to do and you would like to know how you can do this. If my assumption is correct, you can do this by following the bellow given pseudo-code:
1) Get the user input and store it in a variable. Let's say this variable is "in".
2) Use "in" to calculate the number of iterations needed and store this in a new variable. Let's say this new variable is "n". (I believe you have come up with a formula to calculate this.)
3) Run the for loop of "n" number of times.
For more information on "for loops", refer the link given below:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!