Undefined function for input argument of type double

8 visualizzazioni (ultimi 30 giorni)
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)),

Risposta accettata

Star Strider
Star Strider il 7 Apr 2016
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)),
  2 Commenti
Amey
Amey il 7 Apr 2016
yes that worked, but instead of using zeros or ones, i initiated P using for loop below because it was messing with my output. Oh & i removed C2 from the code mistakenly. thank you!
for n=1:1:t; for m=1:1:x-1; P(m,n)=3500; end end
Star Strider
Star Strider il 7 Apr 2016
My pleasure!
Another way to initialise ‘P’ to be a constant array with all elements as 3500 is:
P = ones(x-1,t)*3500;

Accedi per commentare.

Più risposte (1)

Chad Greene
Chad Greene il 6 Apr 2016
Yesterday you most likely had a variable P that you were tinkering with, so when you ran the loop it was able to access actual values in P(m,n). But running the code you posted, P does not exist before you try to access values inside P.

Community Treasure Hunt

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

Start Hunting!

Translated by