Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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 回表示 (過去 30 日間)
Damian Sztangierski
Damian Sztangierski 2019 年 1 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件のコメント
Damian Sztangierski
Damian Sztangierski 2019 年 1 月 7 日
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 2019 年 1 月 7 日
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

回答 (0 件)

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by