问题描述
我有这些未知数和方程:u1,u2,... u10和eq1,eq2,... eq10。我目前正在使用vpasolve
解决它们通常它们是值得计算的,但有时它们的值很低(
所以这将意味着像这样:
VERIF =零(10); (1)= 0
写入'u1'
结束
$
...等等每10个未知数。
vpasolve
会有类似的方式来决定是否写入未知数和方程式。
这个地方,我应该检查它删除是好的。如果u1 verif(1),则这是
= 1;
我的问题是我不知道如何正确写入第一个代码以及如何执行更容易获得100个未知数(类似于for循环)。
编辑1
这是一个for循环。
编辑2
我曾经和一位Java开发者交谈过,他向我解释说有些东西是不可能的(或者应该避免)结论是,我应该在其他地方准备方程式 所以这就是现在的样子,请说是否有其他错误(我只是一名化学家): 还有一个关于我遇到同样问题的其他问题的问题...我应该删除它们还是将链接放在这里? func5 抱歉,评论栏目没有完成,但主要问题(以及其他问题) I have these unknowns and equations: u1,u2,...u10 and eq1,eq2,...eq10.I am currently solving them using vpasolveUsually they are worth calculating, but sometimes their values are so low (<0.0001) that I would like to eliminate them, and after vpasolve solves the rest (some 10 minutes) I should verify if it was wrong or not to eliminate the unknowns. So this would mean something like: ... and so on for every 10 unknowns. My problem is that I don't know how to correctly write the first code and how to do it more easily for 100 unknowns (something like a for loop). EDIT 1This is all inside a for loop. EDIT 2 I have spoken to a Java developer and he explained to me that some things are not possible (or should be avoided) because of the way matlab works. The conclusion was that I should prepare the equations So this is how it looks like now, please say if there is something else wrong that I cannot see (I am just a chemist): And a question about my other questions that suffer from the same problem... should I delete them, or place a link to here? So after rearranging things it looks like this: init5 func5 r=sym('r',[1 12]); sorry about commented lines, they are not done, but main problem of question (and other past questions) is solved and main program 这篇关于matlab使得如果决定写一些函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! vpasolve
,而不是<
verif = zeros(10); %去除未知数的假值
eq = [eq1,eq2 ... eq10]; %原始eq的
eq(2,:)= eq(1,:); %eq的我可以修改
for循环
syms u1 u2 ... u10;
[u1,u2 ... u10] = vpasolve(eq(2,:),[u1,u2 ... u10];
%这是验证我的假设的地方
%注意,u1 ... u4不以这种方式来判断
如果验证(5)= 1
%验证我需要
如果%验证返回假设是错误的 - 这通常不会发生
eq(2,5)= eq(1,5);
verif(5)= 0;%再次作出这个假设之前等待几个循环
再次运行for循环
end
end
...
if u5 eq(2,5)=(u5 == 0) ;
verif(5)= 1;
end
...
end for
$ b (2)= 27.5 / 56;%浓度(%)浓度(b2)=(b3)= 23.5 / 56;%浓度Fe3 baie
om(4)= 1;%conc baza biureta
om(5)= 5/1000; (6)= 50/1000; %volumul la care se aduce solutia din pahar
om(7)= 1/1000; %volumul de baza adaugat pt iteratieva disparea cand se va autorecalcula sau va deveni v initial si va varia
digits(6)
vb0max = uint8((om(1)+ om( 3))* 10); (1)= om(1)* om(5)/ om(6);(b) %浓度1 - 酸浓度稀释剂b b b b b b 1 1 H 2 + Fe 2 + 3 -Fe 3+ 4 -SO 4 2-5-HSO 4 -16-FeHSO 4 + 7 -FeSO 4 8 -FeHSO 4 + 2 + 9-FeSO 4 + 10-Fe(SO 4)2 -11-FeOH 2 + 12-Fe(OH)2 + 13 -Fe(OH)3 14 -OH-15-Na +
c =零(15,vb0max);
ct = zeros(4,vb0max); %matricea conc totale timp real 4-OH
v =零(4,vb0max); %matricea volume in timp real 1-vt 2-vb 3-v1 4-v3
%concentratii totale
v(1,1)= om(6);
ct(1,1)= 2 * cct(1);
ct(2,1)= om(2)* om(5)/ v(1,1);
ct(3,1)= om(3)* om(5)/ v(1,1); (4)=(cct(1)+ ct(2,1)+ 3/2 * ct(3,1))* om(6)
t = animatedline;
轴([0,vb0max + 1,0,7])
r = sym('r',[112]);
eq = [ct(1,j)-r (5)-r(6)-r(8),0,0.5,0,0; (2,j)-r(6)-r(7),NaN,NaN,0,0; (8)-r(9)-r(10)-r(11)-r(12),NaN,NaN,0,0; (5)-r(6)-r(7)-r(8)-r(9)-2 * r(10),NaN, NaN,0,0;
r(4)* r(1)* 10 ^ 1.98,NaN,NaN,0,0;
r(4)* r(1)* r(2)* 10 ^ 1.08,NaN,NaN,0,0;
r(4)* r(2)* 10 ^ 2.25,NaN,NaN,0,0; (4)* r(1)* r(3)* 10 ^ 2.48,NaN,NaN,0,0;
r(4)* r(3)* 10 ^ 4.04,NaN,NaN,0,0;
r(4)^ 2 * r(3)* 10 ^ 5.38,NaN,NaN,0,0; (3)* r(3)/ r(1),NaN,NaN,0,0;
2.5 * 10 ^( - 3)* r(3)/ r(1)^ 2,NaN,NaN,0,0];
eq(:,6)= eq(:,1);
r = vpasolve(r == transpose(eq(:6)),r,eq(:,2:3));如果等式(eq(i,4),1)
(eq(i,6)> 0.0001),则b = b
$ b验证
eq(i,4)= 0;
eq(i,6)= eq(i,1);
%redo vpasolve
end
end
end
$ b%for i = 5:12
%if r1 %eq(i,6)= 0
%eq(i,4)= 1
%if r1 %end
%end
C(1,J)= r.r1; C(2,j)的= r.r2; C(3,j)的= r.r3; C(4,j)的= r.r4; C(5, j)的= r.r5; C(6,j)的= r.r6; C(7,J)= r.r7; C(8,J)= r.r8; C(9,J)= r.r9 ; C(10,j)的= r.r10; C(11,j)的= r.r11; C(12,j)的= r.r12;
$ b 和主程序
init5
j = 1:vb0max
func5
v(1,j + 1)= v(1,j)+ om(7) (2,j + 1)= v(2,j)+ om(7); (1,j + 1)=(ct(1,j)* v(1,j)-om(4)* om(7))/ v(1,j + 1) (3,j + 1)= ct(3,j)* v(1,j)/ v(1,j + 1) (2,j + 1)= ct(2,j)* v(1,j)/ v(1,j + 1)
ct(4,j)= 10 ^( - 14)/ ct(1,j); pH(j)= - log10(ct(1,j)); addpoints(t,v(2,j)* 1000,pH(j)); drawnow
pause(0.05 )
end
verif=zeros(10); %false value for removing unknowns
syms if verif(1)=0
write 'u1'
end
vpasolve
would have a similar way of deciding if the unknowns and equations are written.This is the place that I should check it removing was OK. And this is the place where the <0.0001 decision is made:if u1<0.0001
verif(1)=1;
vpasolve
needs elsewhere, not with an if
within it.verif=zeros(10); %false value for removing unknowns
eq=[eq1,eq2...eq10]; %original eq's
eq(2,:)=eq(1,:); %eq's I can modify
for loop
syms u1 u2...u10;
[u1,u2...u10]=vpasolve(eq(2,:),[u1,u2...u10];
%this is where the verification of my assumption should take place
%to note that u1...u4 are not to be judged this way
if verif(5)=1
%the verification I need
if %verification returns that the assumption was wrong-this normally does not happen
eq(2,5)=eq(1,5);
verif(5)=0; %wait a few loops before making that assumption again
run the for loop again
end
end
...
if u5<0,0001
eq(2,5)=(u5==0);
verif(5)=1;
end
...
end for
om(1)=2.76; %conc acid baie
om(2)=27.5/56; %conc Fe2 baie
om(3)=23.5/56; %conc Fe3 baie
om(4)=1; %conc baza biureta
om(5)=5/1000; %volum acid luat in pahar
om(6)=50/1000; %volumul la care se aduce solutia din pahar
om(7)=1/1000; %volumul de baza adaugat pt iteratie- va disparea cand se va autorecalcula sau va deveni v initial si va varia
digits(6)
vb0max=uint8((om(1)+om(3))*10); %volum baza pt titrare acid (fara Fe)-se va sterge pt ca se va face altfel
cct(1)=om(1)*om(5)/om(6); %conc constanta 1 - acid dupa dilutie
%1-H^+ 2-Fe^2+ 3-Fe^3+ 4-SO4^2- 5-HSO4^- 6-FeHSO4^+ 7-FeSO4 8-FeHSO4^2+ 9-FeSO4^+ 10-Fe(SO4)2^- 11-FeOH^2+ 12-Fe(OH)2^+ 13-Fe(OH)3???0 14-OH^- 15-Na+
c=zeros(15,vb0max);
ct=zeros(4,vb0max); %matricea conc totale in timp real 4-OH
v=zeros(4,vb0max); %matricea volume in timp real 1-vt 2-vb 3-v1 4-v3
%concentratii totale
v(1,1)=om(6);
ct(1,1)=2*cct(1);
ct(2,1)=om(2)*om(5)/v(1,1);
ct(3,1)=om(3)*om(5)/v(1,1);
cct(4)=(cct(1)+ct(2,1)+3/2*ct(3,1))*om(6);
t = animatedline;
axis([0,vb0max+1,0,7])
eq=[ct(1,j)-r(5)-r(6)-r(8) , 0, 0.5, 0, 0;
ct(2,j)-r(6)-r(7) , NaN, NaN, 0, 0;
ct(3,j)-r(8)-r(9)-r(10)-r(11)-r(12) , NaN, NaN, 0, 0;
cct(4)/v(1,j)-r(5)-r(6)-r(7)-r(8)-r(9)-2*r(10), NaN, NaN, 0, 0;
r(4)*r(1)*10^1.98 , NaN, NaN, 0, 0;
r(4)*r(1)*r(2)*10^1.08 , NaN, NaN, 0, 0;
r(4)*r(2)*10^2.25 , NaN, NaN, 0, 0;
r(4)*r(1)*r(3)*10^2.48 , NaN, NaN, 0, 0;
r(4)*r(3)*10^4.04 , NaN, NaN, 0, 0;
r(4)^2*r(3)*10^5.38 , NaN, NaN, 0, 0;
1.9*10^(-3)*r(3)/r(1) , NaN, NaN, 0, 0;
2.5*10^(-3)*r(3)/r(1)^2 , NaN, NaN, 0, 0];
eq(:,6)=eq(:,1);
r = vpasolve(r==transpose(eq(:,6)), r,eq(:,2:3));
%verify
for i=5:12
if isequal(eq(i,4),1)
if eq(i,6)>0.0001
eq(i,4)=0;
eq(i,6)=eq(i,1);
%redo vpasolve
end
end
end
%for i=5:12
%if r1<0,00001
%eq(i,6)=0
%eq(i,4)=1
%if r1<0
%end
%end
c(1,j)=r.r1;c(2,j)=r.r2;c(3,j)=r.r3;c(4,j)=r.r4;c(5,j)=r.r5;c(6,j)=r.r6;c(7,j)=r.r7;c(8,j)=r.r8;c(9,j)=r.r9;c(10,j)=r.r10;c(11,j)=r.r11;c(12,j)=r.r12;
init5
for j=1:vb0max
func5
v(1,j+1)=v(1,j)+om(7); %v total
v(2,j+1)=v(2,j)+om(7); %vb
ct(1,j+1)=(ct(1,j)*v(1,j)-om(4)*om(7))/v(1,j+1);
ct(3,j+1)=ct(3,j)*v(1,j)/v(1,j+1);
ct(2,j+1)=ct(2,j)*v(1,j)/v(1,j+1);
ct(4,j)=10^(-14)/ct(1,j); %OH t
pH(j)=-log10(ct(1,j));addpoints(t,v(2,j)*1000,pH(j));drawnow
pause(0.05)
end