How can i put this recurring calculation into a for loop
1 view (last 30 days)
Show older comments
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 Comments
Tamir Suliman
on 2 Dec 2016
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.
Answers (1)
Sid Jhaveri
on 6 Dec 2016
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!