how to create a loop function

first of all I am new in matlab. And I have a code like this:
k=1.4; z=200
for i=330:-1:6;
for j=330:-1:6;
x(i)=i;
y(j)=(x(i-1)/x(i))^((k-1)/k)*z;
%now I want to repeat this such as
y(j-1)=(x(i-2)/x(i-1))^((k-1)/k)*y(j);
end
end
can anyone tell me how to correct this?? thx a lot
[EDITED, Jan, Please apply code formatting - Thanks]

1 comentario

David Young
David Young el 6 de Mzo. de 2015
Please use the "{} Code" button to format your code. It's then much easier to read.
Please also can you say what is wrong - an error message, or an incorrect result?

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 6 de Mzo. de 2015

0 votos

It is impossible to correct a piece of code, if this code is all available information. The wanted result cannot be guessed.
Currently it looks strange, that the elements of y(j-1) are overwritten in the next iteration.
Alexandru
Alexandru el 6 de Mzo. de 2015

0 votos

@ok David I'll take into account next time when I write a code.
@Jan, I don not know if the code is correct or not, let's try in another way. Let's say x-is pressure, y-is temperature, z is initial temperature. I have a tank with pressurized air, and I release the air from the tank, then the pressure decrease and also temperature decrease, and I want to see this how, step by step.
Just a simple example if I have 330 bars and I am going to 329 in my equation enters the temperature corresponding at 330 bars, initial temperature, but if I am going from 329 bars to 328 I need the temperature value corresponding at 329 bars (meaning the value from previous iteration) and so on... I don't know if I was clear or not. After that I want to plot all this x- values as a vector

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Mzo. de 2015

Respondida:

el 6 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by