MATLAB: Undefined function for input argument of type double

doublefunctioninput

When i saved my code yesterday it was working fine but when i run it now, I am getting this error "Undefined function 'P' for input arguments of type 'double'". Why is that?
L=5100; delta_y=250; delta_z=30; Pini=3500; phi=0.2; k=10; ct=3*10^-5; B=1.25;mu=3; rw=0.25; qc=100; A=delta_z*delta_y; delta_t=10; delta_x=300;
X=150:300:4950; x=length(X);
T=1:10:100; t=length(T);
C1=158*phi*mu*ct/k;
for m=2:1:x-1
for n=1:1:t
P(m,n+1)=((-C1*delta_x^2*P(m,n)/delta_t)+C2*delta_x-P(m+1,n+1)-P(m-1,n+1))/-(2+C1*delta_x^2/delta_t);
end
end
plot (X,P(m,1),'*',X,P(m,6),'+',X,P(m,11),'x');
xlabel ('Distance');
ylabel ('Pressure');
title ('Symmetry Test');
disp (P(m,1)),
disp (P(m,6)),
disp (P(m,11)),

Best Answer

I would preallocate ‘P’ and provide a value for ‘C2’.
This runs, I leave it to you to determine if it produces the results you want:
L=5100; delta_y=250; delta_z=30; Pini=3500; phi=0.2; k=10; ct=3*10^-5; B=1.25;mu=3; rw=0.25; qc=100; A=delta_z*delta_y; delta_t=10; delta_x=300;
X=150:300:4950; x=length(X);
T=1:10:100; t=length(T);
C1=158*phi*mu*ct/k;
C2 = 1; % <— Insert Correct Value
P = zeros(x, t+1); % <— Preallocate With Something
for m=2:1:x-1
for n=1:1:t
P(m,n+1)=((-C1*delta_x^2*P(m,n)/delta_t)+C2*delta_x-P(m+1,n+1)-P(m-1,n+1))/-(2+C1*delta_x^2/delta_t);
end
end
plot (X,P(m,1),'*',X,P(m,6),'+',X,P(m,11),'x');
xlabel ('Distance');
ylabel ('Pressure');
title ('Symmetry Test');
disp (P(m,1)),
disp (P(m,6)),
disp (P(m,11)),