for i = 1:19
P(i) = [2.8*10^-4:0.1*10^-4:4.2*10^-4]
I cannot figure out how to fix my loop

3 件のコメント

Jacob
Jacob 2014 年 2 月 25 日
for i = 1:15*****
dpb
dpb 2014 年 2 月 26 日
From what you're showing, you don't need (or want) a loop at all.
doc colon
and read the "Getting Started" section in help on manipulating arrays in Matlab to begin to get the picture.
per isakson
per isakson 2014 年 2 月 26 日
P = [2.8e-4:1e-5:4.2e-4];
and
P = [2.8*10^-4:0.1*10^-4:4.2*10^-4];
return identical results.

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

 採用された回答

Rick Rosson
Rick Rosson 2014 年 2 月 26 日
編集済み: Rick Rosson 2014 年 2 月 26 日

0 投票

No need for a for loop, no need for square brackets. Also, might as well pull common scale factor out using distributive property:
P = (2.8:0.1:4.2)*1e-4;

1 件のコメント

Jacob
Jacob 2014 年 2 月 26 日
Thanks for your help, but I apologize I did not put the entire code on the question yesterday.
for i = 1:15
P = 2.8e-4:.1e-4:4.2e-4; ???
Kw(i) = 10^-14;
Kh(i) = 10^-1.46;
Ka1(i) = 10^-6.3;
Ka2(i) = 10^-10.3;
func(i) = @(ph,P)Kw/(10^-ph)+(Ka1*Kh*P)/(10^-ph)+(2*Ka1*Ka2*Kh*P)/(10^-ph)^2-(10^-ph);
ph(i) =7;
xl(i) = -20;
xu(i) = 20;
es(i) = 0.1;
[ phout(i), iter(i) ] = bisect( func,xl,xu,es,P )
end

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2014 年 2 月 25 日

コメント済み:

2014 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by