How to fix this error?

2 Ansichten (letzte 30 Tage)
Habib
Habib am 11 Mai 2017
Beantwortet: usha shree am 9 Aug. 2019
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 Kommentar
KSSV
KSSV am 11 Mai 2017
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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

KL
KL am 11 Mai 2017
Bearbeitet: KL am 11 Mai 2017
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 Kommentare
Habib
Habib am 11 Mai 2017
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 am 11 Mai 2017
Bearbeitet: KL am 11 Mai 2017
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.

Melden Sie sich an, um zu kommentieren.


usha shree
usha shree am 9 Aug. 2019
one dimensional error with two elements

Community Treasure Hunt

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

Start Hunting!

Translated by