フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I need help storing all column vectors from a for loop in an array

1 回表示 (過去 30 日間)
Abigail Grein
Abigail Grein 2018 年 12 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I feel like the solution is right on the tip of my tongue and I just can't figure it out. This is my code:
clc; close all; clear;
delZ=1/20;
alpha=1/4;
delT=alpha*delZ^2;
maxT=2/delT;
N=20;
W=[0;ones(20,1)];
We=[0;ones(20,1)];
for k=1:4
for ii=2:N
W(ii)=We(ii)+alpha*(We(ii+1)-2*We(ii)+We(ii-1));
end
We=W;
end
I would like to have each kth iteration of W stored in an array so I can see the progression, and I can't seem to conceptualize how to do it! Any help is greatly appreciated.

回答 (1 件)

Koundinya
Koundinya 2018 年 12 月 12 日
編集済み: Koundinya 2018 年 12 月 12 日
You could create a new array, W_k with each coulmn representing the value of W after every iteration :
clc; close all; clear;
delZ=1/20;
alpha=1/4;
delT=alpha*delZ^2;
maxT=2/delT;
N=20;
W=[0;ones(20,1)];
We=[0;ones(20,1)];
% Create a new array W_k, with the first column equal to W and
% subsequent columns would contain value of W after every iteration
W_k=W;
for k=1:4
for ii=2:N
W(ii)=We(ii)+alpha*(We(ii+1)-2*We(ii)+We(ii-1));
end
We=W;
% Append W (after every kth iteration) to W_k horizontally
W_k=[W_k W];
end

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by