for loop in a for loop does not work

I'm having a problem with my script about my final project.So I have 2 variables and basicly x starts with 10 then goes to 500 with every time t increase with a 0.25 range.(tinitial=0.25) And with every step of this the variables should stop when y almost equals to 250. So I used for loop in a for loop. But when I run the code it gives value of y=-503.7667. I couldnt see where the problem is. Here's my script;

1 件のコメント

Ameer Hamza
Ameer Hamza 2018 年 5 月 29 日
There is no need to remove the text code. Just properly format it by pressing the {} symbol in the question box.

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 29 日

0 投票

This just means that y never come close to 250 with a margin of 0.1, Try increasing the margin
if abs(y-250)<10
Or check what are the values of y produced by the loop by saving all the values
count = 1;
for x=10:10:500
for t=0.25:0.25:11.15
y(count)=2*sqrt(E*t)*tan(alfab)*((1/sqrt(pi))*exp(-(x/2*sqrt(E*t))^2)-(x/sqrt(E*t))*erfc(x/(2*sqrt(E*t))));
count = count+1;
end
end
And from values in y vector, you can check what are the values taken by y and how much closer to 250 does the value come.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

タグ

質問済み:

dj
2018 年 5 月 29 日

編集済み:

dj
2018 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by