Why am I not getting multiple graphs after iteration of the following equation, I am using two 'for' loops
1 回表示 (過去 30 日間)
古いコメントを表示
Equation: F"= G(G^2+lambda*gamma^2)/(G^2+gamma^2)
for different values of parameter 'G' and parameter 'gamma' are calculated and plotted but I not getting those graphs
here's the code that I've used:
global lambda gama
lambda=1;
qq=[-0.6777 -0.7712 -0.8737];
pp=[0.2:0.2:8];
for i=1:numel(pp);
for G=qq;
gama=pp(i);
Fss(i)= G*(G^2+gama^2)/(G^2+lambda*gama^2)
end
end
plot(pp,Fss);hold on
0 件のコメント
採用された回答
Geoff Hayes
2017 年 12 月 11 日
naygarp - the problem is that you are overwriting your values in FSS found in the previous loop with those values in the current loop
Fss(i)= G*(G^2+gama^2)/(G^2+lambda*gama^2)
Your loops are iterating over i and G and so you need to take that into account when updating FSS. Consider the following instead
for i=1:numel(pp);
k = 1;
for G=qq;
gama=pp(i);
Fss(i,k)= G*(G^2+gama^2)/(G^2+lambda*gama^2);
k = k + 1;
end
end
Note that FSS will now be a 40x3 matrix where each column is set for each iteration of the outer loop.
As an aside, you may want to consider pre-allocating (or pre-sizing) your matrix before iterating. Also, reconsider your use of global variables - are they really necessary? If you create a function (rather than a script) your function can return any variables/values that are needed outside of it.
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!