Unable to perform assignment because the left and right sides have a different number of elements.

조회 수: 2 (최근 30일)
Hi all
When I run the attached code, I get the error message:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in DynamicOptimization10Jan2019>myModel (line 90)
dxdt(1)= -2.85.*(1/((1/0.00639039)+(1/k)).*12.54.*x.*x.*(1-(2.69636.*x)/(1+(2.69636.*x))));
Error in DynamicOptimization10Jan2019>@(t,x)myModel(t,x,k) (line 81)
[t,x] = ode15s(@(t,x)myModel(t,x,k),time,x0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in DynamicOptimization10Jan2019>myObj (line 81)
[t,x] = ode15s(@(t,x)myModel(t,x,k),time,x0);
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in DynamicOptimization10Jan2019 (line 3)
k = fminsearch(@myObj,k0);
I know the error I am getting implies that I am trying to put more elements into less elements, or vice versa. However, I do not know how to make elements equal.
please help.
Kind Regards
  댓글 수: 16
Dursman Mchabe
Dursman Mchabe 2019년 1월 10일
The initial conditions are:
x0 = 9.54992586;
y0 = 19.89;
z0 = 0;
w0 = 0;
Dursman Mchabe
Dursman Mchabe 2019년 1월 11일
I have found partial success when using lsqcurvefit. It can estimate k. Yet I don't know how to do sensivity analysis and to determine confidence interval without the objective function. Please see the code below.
function KineticModelat30deg
function C=KineticModel(k,t)
c0=[9.54992586;19.89;0;0];
[T,Cv]=ode45(@ODEs,t,c0);
%
function dC=ODEs(t,c)
dcdt=zeros(4,1);
dcdt(1)= -2.85*(1/((1/0.00639039)+(1/k(1)))*12.54*c(2)*c(1)*(1-(k(2)*c(1))/(1+(k(2)*c(1)))));
dcdt(2)= -(1/((1/0.00639039)+(1/k(1)))*12.54*c(2)*c(1)*(1-(k(2)*c(1))/(1+(k(2)*c(1)))));
dcdt(3)= (1/((1/0.00639039)+(1/k(1)))*12.54*c(2)*c(1)*(1-(k(2)*c(1))/(1+(k(2)*c(1)))));
dcdt(4)= (1/((1/0.00639039)+(1/k(1)))*12.54*c(2)*c(1)*(1-(k(2)*c(1))/(1+(k(2)*c(1)))));
dC=dcdt;
end
C=Cv;
end
t=[1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
];
c=[9.54992586 19.89 0 0
5.623413252 18.51227628 1.377723722 0.000176583
2.884031503 17.5510897 2.338910301 0.000584451
0.489778819 16.71100104 3.178998962 0.004671909
0.048977882 16.55633404 3.333665957 0.048352564
0.046773514 16.55556058 3.33443942 0.050608503
0.032359366 16.55050298 3.339497016 0.072770512
0.022908677 16.54718695 3.342813047 0.101976407
0.016595869 16.54497193 3.345028067 0.139244055
0.014125375 16.54410509 3.345894907 0.16245708
0.011748976 16.54327127 3.346728731 0.193464978
0.01 16.54265759 3.347342407 0.225067572
0.00851138 16.54213527 3.34786473 0.26139843
0.007585776 16.5418105 3.348189503 0.290553969
0.00691831 16.5415763 3.348423702 0.315962812
0.006309573 16.54136271 3.348637294 0.34334241
];
k0=[0.1;50];
[k,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@KineticModel,k0,t,c);
fprintf(1,'\tRate and Adsorption constants:\n')
for i = 1:length(k)
fprintf(1, '\t\tk(%d) = %8.5f\n', i, k(i))
end
tv = linspace(min(t), max(t));
Cfit = KineticModel(k, tv);
figure(1)
plot(t, c, 'v')
hold on
plot(tv, Cfit);
hold off
xlabel('Time (sec)')
ylabel('Concentration (mol/m^3)')
legend('Exp-H^+', 'Exp-CaCO_3', 'Exp-Ca^2+', 'Exp-HCO^-_3','Mod-H^+', 'Mod-CaCO_3', 'Mod-Ca^2+', 'Mod-HCO^-_3', 'Location','E')
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by