Unrecognized function or variable 't'.

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 日

0 投票

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 日

0 投票

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 件のコメント

John D'Errico
John D'Errico 2022 年 2 月 28 日
Please post comments as comments, not as answers.
Sorry though, I don't do anything via mail.
If you want to add a comment that includes what seems relevant, you can, but make sure it has sufficient information, else we would still be at a loss.
Dimitrios Samaras
Dimitrios Samaras 2022 年 3 月 1 日
I will attach to you the relevant paper. If you can take a look, you would help me a lot. I will also take a look again, in order to find something interesting.
John D'Errico
John D'Errico 2022 年 3 月 1 日
編集済み: John D'Errico 2022 年 3 月 1 日
A quick read of the paper shows that t should just be time. They are solving a classic PDE, based on Fick's law of diffusion. The solution has t in it, as time. And it would appear that t varies roughly from 0 to around 100 from the plot.
You can even see the same equation in there that has t in it, in their paper as c(x,t).
So t should just be a vector like this:
t = linspace(0,100);
Dimitrios Samaras
Dimitrios Samaras 2022 年 3 月 1 日
Thank you very much, I also get an error with x, as mentioned above, which I solved with puting the below vector:
x = linspace(0,1);
After, I get an error about c1. What should I do?
Unrecognized function or variable 'c1'.
Walter Roberson
Walter Roberson 2022 年 3 月 1 日
c1 = zeros(length(t), length(x));
before the for loops.
Dimitrios Samaras
Dimitrios Samaras 2022 年 3 月 1 日
Thank you. My code is running and the chart is appearing but I get this message
Index in position 1 exceeds array bounds. Index must not exceed 100.
Walter Roberson
Walter Roberson 2022 年 3 月 1 日
x = linspace(0,1,105);
Dimitrios Samaras
Dimitrios Samaras 2022 年 3 月 1 日
Same problem. Maybe I should do this in t?
Torsten
Torsten 2022 年 3 月 1 日
編集済み: Torsten 2022 年 3 月 1 日
L = 0.001;
D1 = 1e-10;
Ci = 1.0;
t = linspace(0,1,100);
x = linspace(0,L,100);
c1 = zeros(numel(t),numel(x));
for i = 1:numel(t)
for j = 1:numel(x)
for n = 0:200
c1(i,j) = c1(i,j)+cos((2*n+1)*pi*x(j)/(2*L))*exp(-D1*((2*n+1)*pi/(2*L))^2*t(i));
end
c1(i,j) = c1(i,j)*2/L*Ci
end
end
c1 = c1/c1(1,1);
Dimitrios Samaras
Dimitrios Samaras 2022 年 3 月 1 日
Still the same problem.
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
t = linspace(0,100);
x = linspace(0,0.001,105);
c1 = zeros(length(t), length(x));
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')
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by