Index exceeds the number of array elements
显示 更早的评论
Hello All, I'm encountring the following error when I run my code: Index exceeds the number of array elements. My code is simple and shown below:
format longg
syms p1
nm = 3e15;
s01=1;
v1=4.82e20;
tao00=1e-13;
p00=3;
q00=21;
q11=10.6;
R=1.9872036e-3;
T=295;
V1=16.7;
K1=3.27e19;
t1=linspace(1,1e6,10);
taop1=3.6;
S1=4.7;
A1=4.74e3;
Nm = A1*nm;
W1=(Nm/(K1*V1));
y1=q00;
a1= ((s01*tao00*v1)/(nm))*exp((y1)/(R*T));
Z1=(1/(1+a1*p00));
Y1 = (p00/(1+(a1*p00)));
eq1 = ((t1./taop1)==(log(p00./p1))+((a1.*W1).*(Z1-(1./(1+a1.*p1))+log(((1+a1.*p1)./p1).*Y1))));
for i=t1
pp1=0;
pp1(i) = vpa(vpasolve(eq1(i),p1),11);
end
pp1;
% loglog(t1,pp1,'o')
% ylim([1e-11 1e-2])
% xlim([10 1e6])
Thank you all for the help in advance.
2 个评论
N/A
2023-1-12
Walter Roberson
2023-1-12
Assign the results of the vpasolve to a variable. Test to see if the variable is empty or has more one value.
采纳的回答
更多回答(1 个)
I suggest you insert values for p1 and solve for t1. This will be easier than the other way round.
format longg
syms p1 t1
nm = 3e15;
s01=1;
v1=4.82e20;
tao00=1e-13;
p00=3;
q00=21;
q11=10.6;
R=1.9872036e-3;
T=295;
V1=16.7;
K1=3.27e19;
T1=linspace(1,10,10);
taop1=3.6;
S1=4.7;
A1=4.74e3;
Nm = A1*nm;
W1=(Nm/(K1*V1));
y1=q00;
a1= ((s01*tao00*v1)/(nm))*exp((y1)/(R*T));
Z1=(1/(1+a1*p00));
Y1 = (p00/(1+(a1*p00)));
eq1 = ((t1./taop1)==(log(p00./p1))+((a1.*W1).*(Z1-(1./(1+a1.*p1))+log(((1+a1.*p1)./p1).*Y1))));
for i=1:numel(T1)
pp1(i) = double(vpasolve(subs(eq1,t1,T1(i)),p1,11));
end
pp1.'
5 个评论
N/A
2023-1-12
I'm still getting this error, even when I tried to increase n in T1=linspace. For some reason, it only works for n up to T1=Linspace(1,1e6,117).
We must be able to reproduce the error. So:
What is the error message ?
How do you set T1 when you get the error message ?
N/A
2023-1-12
I didn't use
pp1(i) = vpa(solve(eq1(i),p1,'IgnoreAnalyticConstraints',1),6);
anywhere in the code I provided.
And the decrease towards 0 has nearly ended at t=10. There is no need to solve up to 1e6.
But if you want: T1 = linspace(1,1e6,100) will also work:
format longg
syms p1 t1
nm = 3e15;
s01=1;
v1=4.82e20;
tao00=1e-13;
p00=3;
q00=21;
q11=10.6;
R=1.9872036e-3;
T=295;
V1=16.7;
K1=3.27e19;
T1=linspace(1,1e6,100);
taop1=3.6;
S1=4.7;
A1=4.74e3;
Nm = A1*nm;
W1=(Nm/(K1*V1));
y1=q00;
a1= ((s01*tao00*v1)/(nm))*exp((y1)/(R*T));
Z1=(1/(1+a1*p00));
Y1 = (p00/(1+(a1*p00)));
eq1 = ((t1./taop1)==(log(p00./p1))+((a1.*W1).*(Z1-(1./(1+a1.*p1))+log(((1+a1.*p1)./p1).*Y1))));
for i=1:numel(T1)
pp1_help = double(vpasolve(subs(eq1,t1,T1(i)),p1,11));
pp1_help = pp1_help(real(pp1_help)>0 & abs(imag(pp1_help))<1e-8);
if ~isempty(pp1_help)
pp1(i) = real(pp1_help(1));
else
pp1(i) = 0.0;
end
end
plot(T1,pp1)
N/A
2023-1-13
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

