フィルターのクリア

Nested loop results in 3d matrix and plot3

1 回表示 (過去 30 日間)
Rajeev kamal
Rajeev kamal 2016 年 1 月 11 日
編集済み: Rajeev kamal 2016 年 1 月 12 日
I am trying to run a nested loop to get three values saved as 3d matrix and then get a 3d plot from them. How can I do this. The values come from Xi+1 = r*Xi(1 − Xi), where i range from 1:50 and r from 2.4 to 4.
###Code####
r=2.4:0.1:4;
for j=1:16;
X(1,1)=.5;
xsav(1,1)=1;
xsav(1,2)=X(1);
r(j)=2.4+j*.1;
for i=1:50;
X(i+1)=r(j)*X(i)*(1-X(i));
end
end
How do I save these values and plot a 3d. (mesh or plot3 or comet3)
  1 件のコメント
Jason Nicholson
Jason Nicholson 2016 年 1 月 11 日
Your code and question are not easy to ready. You probably should try to make it look better.

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

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 1 月 12 日
Rajeev - why does your code define r as
r=2.4:0.1:4;
and then overwrite the jth element on each iteration of the outer for loop with
r(j)=2.4+j*.1;
This shouldn't be necessary since you have already defined r. As for saving the data to X, you can get a two-dimensional matrix/array as
r=2.4:0.1:4;
X = zeros(50,length(r));
for j=1:length(r)
X(1,j)=.5;
for i=1:size(X,1)-1
X(i+1,j)=r(j)*X(i,j)*(1-X(i,j));
end
end
In this case, X will be a 50x17 matrix. It isn't clear to me how you expect to get a 3D matrix from the above code, so please clarify.
As an aside, using i and j as your indexing variables is generally discouraged since MATLAB uses both to represent the imaginary number.
  1 件のコメント
Rajeev kamal
Rajeev kamal 2016 年 1 月 12 日
編集済み: Rajeev kamal 2016 年 1 月 12 日
A 3d matrix was my misunderstanding. This works..Thanks @Geoff Hayes However, I wanted the values of r be included instead of 1 to 17

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by