フィルターのクリア

Matlab code wont disply the figure 2

1 回表示 (過去 30 日間)
Bijaya
Bijaya 2023 年 10 月 13 日
コメント済み: Dyuman Joshi 2023 年 10 月 13 日
c= 1; % unit conversion
L=1; % t=[L]/[c]
C=0.1;
N=1000;
Np=N+1;
dx= L/N;
x=(0:dx:L)';
dt=C*dx/c;
sqrC=C*C;
% step2 convert PDE to linear algebraic equations
A= sparse(Np,Np); % matrix creation as rows,columns
u= zeros(Np,1); % unknowns
b= zeros(Np,1); %RHS
% generate a wave function
u = sin(3*pi*x);
%figure(1);clf;hold on
plot(x,u,'-b','Linewidth',L);
xlabel('x([L])')
ylabel('Amplitude([L])');
title('Intial Wave')
set(gca,'Linewidth',1,'fontsize',12)
box on;
ylim([-1,1]);
uset{1} = u; % future
uset{2} = u; % present
uset{3} = u; % previous
uset{4} = u; % previusly previous
% Apply boundary conditions
A(1,1)= 1; b(1)= 0;
A(Np,Np) = 1; b(Np) = 0;
for i= 2:Np-1
A(i,i) =2 +sqrC*2;
A(i,i-1) = -sqrC;
A(i,i+1) = -sqrC;
b(i) =5*uset{1}(i) - 4*uset{2}(i) + uset{3}(i);
end
%u=A/b
%uset{1}=u;
t=0;
Nt=100000;
for k=0:Nt
t= t+dt;
for i=2:Np-1
b(i) =5*uset{1}(i) - 4*uset{2}(i) + uset{3}(i);
end
u=A\b;
uset{3}=uset{2};
uset{2}= uset{1};
uset{1}=u;
end
if k==1
figure(2); clf; hold on;
xlabel('x')
ylabel('y','amplitude')
set(gca,'Linewidth',1,'fontsize',12)
box on
h=1;
ylim([-1,1])
end
if mod(k,50)==0
% figure(2);
if h~=0; delete(h); end
h = plot(x,u, '-b', 'Linewidth', 2);
title(['Time:' num2str(t)]);
end
Unrecognized function or variable 'h'.

採用された回答

Walter Roberson
Walter Roberson 2023 年 10 月 13 日
h is not initialized so you cannot test
if h~=0; delete(h); end
  2 件のコメント
Bijaya
Bijaya 2023 年 10 月 13 日
移動済み: Dyuman Joshi 2023 年 10 月 13 日
I have already defined h=1; BUT it still keep on giving same error . How do i fix it ?
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 13 日
No, that statement is subjected to a condition i.e. k==1. And as the condition is not satisfied (because the value of k is Nt), h=1 is not executed.
You can directly over-write h (if it has been defined), there's no need to delete it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by