Undefined function for input argument of type double

조회 수: 8 (최근 30일)
Amey
Amey 2016년 4월 6일
댓글: Star Strider 2016년 4월 7일
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)),

채택된 답변

Star Strider
Star Strider 2016년 4월 7일
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
Amey
Amey 2016년 4월 7일
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 2016년 4월 7일
My pleasure!
Another way to initialise ‘P’ to be a constant array with all elements as 3500 is:
P = ones(x-1,t)*3500;

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chad Greene
Chad Greene 2016년 4월 6일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by