Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How do I repeat an iteration with newly generated initial conditions if a statement is false? I wrote code that gives me values i need, however if the difference between the values is not smaller than 0.5, I need the loop to restart.

1 visualizzazione (ultimi 30 giorni)
I need help putting all of this into one big loop
  1. Guess initial value
  2. My code uses the guess to generate multiple T and Z values, these are the imporant ones --> T(5) and Z(4)
  3. If T(5) - (20-55/22*Z(4)) < 0.5 is true then plot (x,T) ,
  4. If it is false then a new guess needs to be generated using (new guess) = (previous guess) - (previous Z4 value) and put into my code to generate another T(5) and Z(4)
  5. The process needs to repeat until step 3 prduces a graph .
This is the code that generates T and Z values
h = 0.01;
A = 8000/11;
T(1)=80;
x(1)=0;
prompt = ('Guess initial Z value');
Z(1) = input(prompt);
for i=2:5
x(i) = x(i-1)+h;
T(i) = T(i-1) + h*Z(i-1)
Z(i) = Z(i-1) + h*(A*(T(i-1)-20));
end
  3 Commenti
Damian Sztangierski
Damian Sztangierski il 7 Gen 2019
Thank you for this, I just tried the code but it says ‘Undefined function or variable ‘genTZ’’ in line 17, how do i get rid of this error?
Damian Sztangierski
Damian Sztangierski il 7 Gen 2019
I have fixed the undefined function issue but now when i run this code i get asked to input the prompt twice and after that i get an error saying the index exceeds matrix dimensions in line 20

Risposte (0)

Questa domanda è chiusa.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by