How to fix this error?

1 回表示 (過去 30 日間)
Habib
Habib 2017 年 5 月 11 日
回答済み: usha shree 2019 年 8 月 9 日
I tried to run below script but "The grid vectors do not define a grid of points that match the given values." error is appeared and it is related to
z1=interp2(T,x,Z,T1,x1);
So how I can fix it?
L=5;
c=1;
n=100;
dt=0.005;
tf=5;
h=L/n;
l=dt*c/h;
l2=l^2;
M=l2*(diag(ones(n,1),1)+diag(ones(n,1),-1));
x=linspace(0,L,n+1);
f=x.*sin(4*pi*x/L);
g=0*x;
t=0;
w=f;
z=(1-l2)*f+f/2*M+dt*g;
t=t+dt;
Z=[];
T=[];
while t<tf
u=2*(1-l2)*z+z*M-w;
z=u;
Z=[Z,z];
T=[T,t];
w=z;
t=t+dt;
end
T1=linspace(0,tf,100);
x1=linspace(0,L,100);
z1=interp2(T,x,Z,T1,x1);
surf(x1,T1,z1);
axis([0 L 0 tf -5 5]);
xlabel('position')
ylabel('time')
zlabel('temperetur')
  1 件のコメント
KSSV
KSSV 2017 年 5 月 11 日
Read the documentation of interp2....and then call the function.
z1=interp2(T,x,Z,T1,x1);
In the above sizes of T,x,Z should be same but they are no tin your case; so the error.

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

回答 (2 件)

KL
KL 2017 年 5 月 11 日
編集済み: KL 2017 年 5 月 11 日
Did you read interp2 documentation ?
In your code,
z1=interp2(T,x,Z,T1,x1);
T and x must be of the same size and similarly T1 und x1. Z must be a matrix containing length(x) rows and length(T) columns.
whos T x Z T1 x1
Name Size Bytes Class Attributes
T 1x1000 8000 double
T1 1x100 800 double
Z 1x101000 808000 double
x 1x101 808 double
x1 1x100 800 double
  2 件のコメント
Habib
Habib 2017 年 5 月 11 日
Thanks. Yes, that is right.
but how I can make them same size? I tried but I didn't understand how do it. Infact, I don't know how i can reduce the size of "Z" and "T" inside "while" loop. the size of "Z" is 1*101000.
KL
KL 2017 年 5 月 11 日
編集済み: KL 2017 年 5 月 11 日
It's hard to understand how you create Z or the relationship between x,T and Z. If you explain that maybe we could help.

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


usha shree
usha shree 2019 年 8 月 9 日
one dimensional error with two elements

カテゴリ

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