Unrecognized function or variable 't'.

조회 수: 15 (최근 30일)
Dimitrios Samaras
Dimitrios Samaras 2022년 2월 28일
댓글: Walter Roberson 2022년 3월 2일
Hello, I'm trying to run the following code,which I found in a paper, but I came up with the following problem
"Unrecognized function or variable 't'."
What should I do in order to fix the problem?
I attach to you the code:
global D1 D2 D3 Ci L
D1 = 10^-10; %cm^2/s
D2 = 10^-6;
D3 = 10^-5;
Ci = 1; % 1 micromolar
L = .001; %200 microns
for n = 0:200
for i = 1:length(t)
for j = 1:length(x)
c1(i,j) = c1(i,j)+2/L*Ci*cos((2*n+1)*pi*x(j)/(2*L))*exp(-D1*((2*n+1)*pi/(2*L))^2*t(i));
end
end
end
c1 = c1/c1(1,1); %scaling to account for infinite value at c1(0,0)
figure
mesh(x,t,c1)
% Az -12 El -6
xlabel('x - Distance(m)')
ylabel('t - Time(s)')
zlabel('c(x,t) - Concentration (M)')
title('Analytical Solution')
pAn1 = c1(5,:);
pAn2 = c1(15,:);
pAn3 = c1(35,:);
pAn4 = c1(75,:);
pAn5 = c1(105,:);
figure
plot(x,pAn1,'b',x,pAn2,'g',x,pAn3,'r',x,pAn4,'m',x,pAn5,'k')
xlabel('x - Distance(m)')
ylabel('c(x,t) - Concentration (M)')
xlim([0 0.0001])
title('Analytical solution at distinct times')
legend('t = .5 s','t = 1.5 s','t = 3.5 s','t = 7.5 s','t = 10.5 s')
Unrecognized function or variable 't'.
Thank you very much for your help, in advance
  댓글 수: 2
Torsten
Torsten 2022년 2월 28일
After you repair the code by supplying a vector t, the same error message will come up with the vector x.
You must supply both x and t to get a plot of the solution of the PDE your infinite series represents.
Dimitrios Samaras
Dimitrios Samaras 2022년 3월 1일
Thank you very much for your help.

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

채택된 답변

John D'Errico
John D'Errico 2022년 2월 28일
편집: John D'Errico 2022년 2월 28일
Contact the authors of the paper, as apparently having submitted crap for code with undefined variables. Worse, it got accepted for publication. SIGH. Such is life. Remember that code, completely by itself and out of context, means absolutely nothing.
t is undefined. We cannot guess what they intended by the variable t. (It seems to be a vector.) And since we don't even see the paper itself, how would we guess at what t should mean?
Ok, wait, I'll check the MATLAB crystall ball (it looks a lot like a snow globe.) It is cloudy for a minute, then it tells me t is the letter after s. When I press it yet more, I see it also comes before u. I hope that helps. It you want more clarity than that, I can check the MATLAB tarot cards, but all they ever tell me is I will either soon come into a large inheritance, or my relatives will come into a large inheritance. I am hoping it is not the latter.
Seriously, t is unknown. You should have the paper in hand, so you could actually read the paper and see how the code reflects what is in the paper. We have only the MATLAB crystal ball.

추가 답변 (1개)

Dimitrios Samaras
Dimitrios Samaras 2022년 2월 28일
Hahaha, that is a good assumption according to the MATLAB crystal ball. In fact, I have the paper, can I send it to you in order to take a look, in a small paragraph, which depicts our problem? I'm trying to figure out what's going on, but I think that I don't have enough knowledge of MATLAB.
  댓글 수: 12
Torsten
Torsten 2022년 3월 1일
편집: Torsten 2022년 3월 1일
That's not what I wrote.
Use
t = linspace(0,1,100);
instead of
t = linspace(0,100);
Walter Roberson
Walter Roberson 2022년 3월 2일
t = linspace(0,1,105);
You can go back to length 100 for x if you want.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by