フィルターのクリア

Is vectorizing this even possible?

1 回表示 (過去 30 日間)
Payton Brown
Payton Brown 2020 年 9 月 17 日
コメント済み: Payton Brown 2020 年 9 月 18 日
vec3(1) = 1;
i = 1;
while i<5
i = i+1;
vec3(i) = (vec3(i-1)+2)^2;
end
vec3

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 17 日
I posted the complete vectorization several days ago; . Unfortunately the person deleted the question.
syms v v0 c
f(v) = (v+c)^2;
f5 = f(f(f(f(f(v0)))));
vec3_5 = expand(subs(f5, c, 2));
v0^32 + 64*v0^31 + 2016*v0^30 + 41600*v0^29 + 631536*v0^28 + 7511168*v0^27 + 72782528*v0^26 + 590011136*v0^25 + 4077667064*v0^24 + 24363708032*v0^23 + 127184607424*v0^22 + 584772138240*v0^21 + 2382767071968*v0^20 + 8644745151232*v0^19 + 28021844462720*v0^18 + 81349497514496*v0^17 + 211814884610908*v0^16 + 494935571753856*v0^15 + 1037540400943680*v0^14 + 1949025086827264*v0^13 + 3273934344609568*v0^12 + 4902203714779904*v0^11 + 6514485357242496*v0^10 + 7638211784159744*v0^9 + 7840967227104336*v0^8 + 6975721989473536*v0^7 + 5305860461727104*v0^6 + 3387252771621376*v0^5 + 1768336935606208*v0^4 + 726328276999680*v0^3 + 220554340195584*v0^2 + 44118436709376*v0 + 4371938082724
Where v0 = 1
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 18 日
Yup ;-)
Using a for loop is not vectorizing . This solution is not vectorized in terms of the number of iterations, but it is vectorized in terms of different initial conditions.
I think it should be possible to calculate what all the terms should be, in terms of binomial coefficients and number of iterations, but the form is not coming to mind immediately.
Payton Brown
Payton Brown 2020 年 9 月 18 日
Thank you so much!

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 9 月 17 日
編集済み: madhan ravi 2020 年 9 月 17 日
A simple for loop is the best and easier to understand:
vec3 = zeros(5,1);
vec3(1) = 1;
for k = 2:5 % edited after Stephen’s comment
vec3(k) = (vec3(k-1)+2)^2;
end
vec3
  2 件のコメント
Stephen23
Stephen23 2020 年 9 月 17 日
Starting the for loop from one will throw an error. Better to start from two:
vec3 = ones(5,1);
for k = 2:5
vec3(k) = (vec3(k-1)+2)^2;
end
madhan ravi
madhan ravi 2020 年 9 月 17 日
Ah thanks Stephen!

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by