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
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
2022-3-1
采纳的回答
更多回答(1 个)
Dimitrios Samaras
2022-2-28
0 个投票
12 个评论
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
2022-3-1
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
2022-3-1
Walter Roberson
2022-3-1
c1 = zeros(length(t), length(x));
before the for loops.
Dimitrios Samaras
2022-3-1
Walter Roberson
2022-3-1
x = linspace(0,1,105);
Dimitrios Samaras
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
2022-3-1
That's not what I wrote.
Use
t = linspace(0,1,100);
instead of
t = linspace(0,100);
Walter Roberson
2022-3-2
t = linspace(0,1,105);
You can go back to length 100 for x if you want.
类别
在 帮助中心 和 File Exchange 中查找有关 General PDEs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!