Unrecognized function or variable 't'.
Afficher commentaires plus anciens
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 commentaires
Torsten
le 28 Fév 2022
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
le 1 Mar 2022
Réponse acceptée
Plus de réponses (1)
Dimitrios Samaras
le 28 Fév 2022
0 votes
12 commentaires
John D'Errico
le 28 Fév 2022
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
le 1 Mar 2022
John D'Errico
le 1 Mar 2022
Modifié(e) : John D'Errico
le 1 Mar 2022
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
le 1 Mar 2022
Walter Roberson
le 1 Mar 2022
c1 = zeros(length(t), length(x));
before the for loops.
Dimitrios Samaras
le 1 Mar 2022
Walter Roberson
le 1 Mar 2022
x = linspace(0,1,105);
Dimitrios Samaras
le 1 Mar 2022
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
le 1 Mar 2022
That's not what I wrote.
Use
t = linspace(0,1,100);
instead of
t = linspace(0,100);
Walter Roberson
le 2 Mar 2022
t = linspace(0,1,105);
You can go back to length 100 for x if you want.
Catégories
En savoir plus sur General PDEs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!