Undefined function for input argument of type double
8 次查看(过去 30 天)
显示 更早的评论
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)),
0 个评论
采纳的回答
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 个评论
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!