フィルターのクリア

Error: Unable to perform assignment because the left and right sides have a different number of elements.(line 25)

2 ビュー (過去 30 日間)
%chebyshev differentiation matrix
function [D,x] = cheb(N)
if N==0,D=0;x=1;return,end
x=cos(pi*(0:N)/N)';
c=[2;ones(N-1,1);2].*(-1).^(0:N)';
X=repmat(x,1,N+1);
dX=X-X';
D=(c*(1./c)')./(dX+(eye(N+1)));
D=D-diag(sum(D'));
end
%Differentiatio matrix and initial data
N=20;
[D,x]=cheb(N);
D2=D^2;
eps=1;
dt=min([.01,50*N^(-4)/eps]);
t=0;
sigma=.10;
r=.12; K=100;
k=2*r/sigma^2;
v=max(exp((k+1)/2)*x-exp((k-1)/2)*x,0);
t=0;
%Differentition matrix and initial data;
%solve pde
tmax=100;tplot=2
nplots=round(tmax/tplot)
plotgap=round(tplot/dt),dt=tplot/plotgap
xx=-1:.025:1; vv=polyval(polyfit(x,v,N),xx);
plotdata=[vv;zeros(nplots,length(xx))]; tdata=t;
for i=1:nplots
for n=1:plotgap
t=t+dt;v=v+dt*(eps*D2*v);
v(1)=exp(((k+1)/2)*x+(((k-1)/2).^2+k)*t)-exp(((k-1)/2)*x+(((k-1)/2)^2)*t);
v(end)=0;
end
vv=polyval(polyfit(x,v,N),xx);
plotdata(i+1,:)=vv;tdata=[tdata;t];
end
clf,subplot('position',[.1 .4 .8 .5])
mesh(xx,tdata,plotdata),grid on
axis([-1 1 0 tmax -1 2]),
view(-60,55),colormap([0 0 0]),xlabel x,ylabel t,zlabel u
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 28 日
Which cheb() function are you using?
.. We need to know in order to figure out what the size of D and x will be.
Asir Tushar
Asir Tushar 2019 年 3 月 29 日
sorry, I am attaching the cheb function

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 3 月 29 日
Your x is a column vector of length N+1. You use all of it in the right hand side of your calculation of v(1) so the right hand side is going to have N+1 elements. You will not be able to fit that into the scalar location v(1).
  5 件のコメント
Asir Tushar
Asir Tushar 2019 年 3 月 30 日
Should I use another loop to store each results ?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by