フィルターのクリア

index out of bounds because numel(uold)=1 Error

1 回表示 (過去 30 日間)
Ishfaq Ahmad Bhat
Ishfaq Ahmad Bhat 2016 年 11 月 23 日
コメント済み: Ishfaq Ahmad Bhat 2016 年 11 月 23 日
Please help in removing the error in matlab code. I tried with changing the variable but that didn't help.
% Defining constants;
L=10; % length of domain in x-direction
tmax=10; % end time
nx=50; % number of nodes in x-direction
nt=50; % number of time steps
dx=L/(nx-1); % Length of space interval
dt=tmax/(nt-1); % Length of time interval
alpha=input('Enter the value of alpha: ');
r=alpha*dt/dx^2;
r2=1-2*r;
% INITIAL CONDITION
t=0;
u=0;
% LOOP OVER TIME STEPS
for m=1:nt
uold=u;
t=t+dt;
% LOOP OVER SPACE STEPS
for i=2:nx-1
u(i)=r*uold(i-1)+r2*uold(i)+r*uold(i+1);
end
end
  1 件のコメント
KSSV
KSSV 2016 年 11 月 23 日
YOur code will work only when u is made a vector. At present u is only scalar equals to 0.

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

採用された回答

Preethi
Preethi 2016 年 11 月 23 日
hi,
initialize u with a vector of zeros instead of '0'. for ex
u =zeros(1,nx-1)
  1 件のコメント
Ishfaq Ahmad Bhat
Ishfaq Ahmad Bhat 2016 年 11 月 23 日
Thanks for help...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by