Loop for forward difference finite method

5 ビュー (過去 30 日間)
Richard Rees
Richard Rees 2019 年 7 月 25 日
コメント済み: Richard Rees 2019 年 7 月 30 日
Good evening everyone,
I have a problem whereby my function stops running at the end of first row and doesn't start up again at the beginning of the next because I do not know to tell it that it has reached the end.
d_d = diff(dd,1,2);
ts = 1440;
% Finds the dimensions of the matrix containing PWP values for each node
sPWP = d_d(:,:);% Starts at the beginning value for each column
sPWP = [d_d, d_d(:,end)]; % Duplicate the end row
[rows, zones] = size(d_d);
dfdx_sim = nan(size(sPWP)); %Preallocate zero matrix based on B dimensions (Saves the CPU reiterating over the same list)
for g = 1:zones
for h = 1:rows
%while g+1<zones
dfdx_sim(g,h) = ((sPWP(g+1,h) - sPWP(g,h)))/ts;
%continue
end
end
Thanks
  2 件のコメント
Stephen23
Stephen23 2019 年 7 月 26 日
編集済み: Stephen23 2019 年 7 月 26 日
When I load your .mat file and run your code I get this error:
Undefined function or variable 'dd'.
Error in sample (line 5)
d_d = diff(dd,1,2);
When I comment-out that line (because you seem to have supplied d_d in the .mat file) I get this error:
Attempted to access sPWP(2,8); index out of bounds because size(sPWP)=[191,7].
Error in sample (line 16)
dfdx_sim(g,h) = ((sPWP(g+1,h) - sPWP(g,h)))/ts;
Please ensure that your code and data demonstrate what you experience. It we cannot reproduce what you are experiencing, then it makes it harder for us to help you.
Richard Rees
Richard Rees 2019 年 7 月 26 日
Good morning, I have uploaded an excel file with the data on.
Thanks

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

採用された回答

SaiDileep Kola
SaiDileep Kola 2019 年 7 月 29 日
I went through your code and I see that you need to swap the arguments “g” and “h” in the equation inside the nested “for” loop
dfdx_sim(h,g) = ((sPWP(h,g+1) - sPWP(h,g)))/ts;
You will get the expected output now.
  1 件のコメント
Richard Rees
Richard Rees 2019 年 7 月 30 日
Hi, thanks for that. I figured out the same thing.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by