How can i put this recurring calculation into a for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Tamir Suliman
el 2 de Dic. de 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.
Respuestas (1)
Sid Jhaveri
el 6 de Dic. de 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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!