l=input('l=');
for t=0:100
if t>2
g=((3/(309*0.0014))*((((0.0000126*(t-2))/l)*80.4)-(l/6)));
elseif t>80
g=l-((80.4/309)*exp(((((-3*0.0000126)/(0.0014*l))*(t-80)))));
else
g=0;
end
disp (g);
end
t=0:100;
plot (t,g)
can someone explain how to plot graph using this coding because the don't get the graph.

1 件のコメント

liyana nadirah
liyana nadirah 2020 年 1 月 27 日
*the graph not show.

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

 採用された回答

Bhaskar R
Bhaskar R 2020 年 1 月 27 日

0 投票

l=input('l=');
g = zeros(1, length(0:100));% initialize g with 0's of length t
c = 1; % counter variable
for t=0:100
if t>2
g(c)=((3/(309*0.0014))*((((0.0000126*(t-2))/l)*80.4)-(l/6)));
elseif t>80
g(c)=l-((80.4/309)*exp(((((-3*0.0000126)/(0.0014*l))*(t-80)))));
else
g(c)=0;
end
c = c+1; % increment counter variable
disp (g);
end
t=0:100;
plot (t,g)

7 件のコメント

liyana nadirah
liyana nadirah 2020 年 1 月 27 日
i get the graph but the data output is repeated. why?
Bhaskar R
Bhaskar R 2020 年 1 月 27 日
Your data is according to your statements and you have used disp(g) to print g for each iteration that is why data output is repeated.
liyana nadirah
liyana nadirah 2020 年 1 月 28 日
so should i delete the comand disp g
Walter Roberson
Walter Roberson 2020 年 1 月 28 日
Yes. Or use logical indexing like I posted
liyana nadirah
liyana nadirah 2020 年 1 月 28 日
for l=0.0002:0.001
g = zeros(1, length(0:100));% initialize g with 0's of length t
c = 1;% counter variable
for t=0:100
if (t(d)>2) && (t(d)<=80)
g(c)=((3/(309*0.0014))*((((0.0000126*(t-2))/l)*80.4)-(l/6)));
elseif t(d)>80
g(c)=l-((80.4/309)*exp(((((-3*0.0000126)/(0.0014*l))*(t-80)))));
else
g(c)=0;
end
c = c+1;% increment counter variable
end
end
disp (g)
t=0:100;
plot(t,g)
xlabel('Day')
ylabel('Cumulative percentage of nutrient release,%')
how about this can you help me fix my nested for loop. and how can i have all the graph for all 'l' in one graph
Walter Roberson
Walter Roberson 2020 年 1 月 28 日
for t=0:100
t is a scalar
if (t(d)>2) && (t(d)<=80)
d is undefined. If d does not happen to be 1, then because t is a scalar, t(d) would be out of range.
for l=0.0002:0.001
every iteration of that loop, every different value of l, you are ovewriting all of g. The result would be the same as if you had only done the last of them, 0.0002 .
Notice by the way that because the default increment is 1, your code
for l=0.0002:0.001
is the same as
for l=0.0002 : 1 : 0.001
so 0.0002 would be used, then 0.0002+1 would be examined and found to be greater than 0.001 so the loop would stop.
liyana nadirah
liyana nadirah 2020 年 1 月 28 日
emmm sorry idon't get it, so
first i should declare d as 1?

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 1 月 27 日
編集済み: Walter Roberson 2020 年 1 月 27 日

0 投票

l = input('l=');
t = 0:100;
g = zeros(size(t));
mask = t>2 & t <= 80
g(mask) = ((3/(309*0.0014))*((((0.0000126*(t(mask)-2))/l)*80.4)-(l/6)));
mask = t>80;
g(mask) = l-((80.4/309)*exp(((((-3*0.0000126)/(0.0014*l))*(t(mask)-80)))));
plot (t,g)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by