Hey Sudipa,
I ran your code on my end and was able to reproduce the errors you encountered. Based on the R2024b definition of the functions you used; I identified two main issues:
Firstly, for line 3 in “state.m” -and “adjoint.m” the use of the MATLAB function “deal()” requires the number of input arguments to be equal to the number of output arguments. You were passing all 22 arguments in your variable “parameters” which was leading to an error.
Assuming you want to pass the first 18 arguments the following change in state.m:
>>[epsilon,gamma,beta,theta1,theta2,mu,Lambda,rho,delta0,r, r0, delta1, d, psi, zeta1, zeta2,alpha,phi] = deal(parameters{1:18});
And the below in adjoint.m:
>>[epsilon,gamma,beta,theta1,theta2,mu,Lambda,r, r0, delta1, d, psi, zeta1, zeta2,alpha,phi,A1,A2] = deal(parameters{1:18});
This should resolve the error.
If you need to pass specific arguments, you can use cell indexing or create a new variable accordingly.
Here's a link to guide you on accessing data in a cell array:
Also, here’s the documentation for the deal() function:
Secondly, in the definition of “adjoint.m”, there was an imbalance in the number of opening and closing parentheses. Assuming the formula was missing parentheses at the end, the following changes resolved the issue:
At line 6:
>> dlambdadt(1) = -(lambda(1)*(Lambda-mu+beta*(1-u(1))*x(1)*x(7)* ...
phi/(x(1)+x(2)+x(3)+x(4))^2-beta*(1-u(1))*x(7)*phi/(x(1)+x(2)+x(3)+x(4)))...
+lambda(2)*(beta*(1-u(1))*x(7)*phi/(x(1)+x(2)+x(3)+x(4))...
-beta*(1-u(1))*x(1)*x(7)*phi/(x(1)+x(2)+x(3)+x(4))^2 ...
+lambda(5)*(theta2*(1-u(1))*x(2)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2 ...
+theta1*(1-u(1))*x(3)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2) ...
+lambda(6)*(-theta2*(1-u(1))*x(2)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2 ...
-theta1*(1-u(1))*x(3)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2)));
And at line 8 :
>>dlambdadt(3) = -(A2+lambda(3)*(-alpha-mu-r0*u(2)-r)+lambda(4)*(r0*u(2)+r)...
+lambda(1)*((1-zeta1)*Lambda+beta*(1-u(1))*x(1)*x(7)*phi/(x(1)+x(2)+x(3)+x(4))^2)...
+lambda(2)*(zeta1*Lambda-beta*(1-u(1))*x(1)*x(7)*phi/(x(1)+x(2)+x(3)+x(4))^2)...
+lambda(5)*(theta2*(1-u(1))*x(2)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2 ...
+theta1*(1-u(1))*x(3)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2 ...
-theta1*(1-u(1))*x(5)*phi/(x(1)+x(2)+x(3)+x(4))) +lambda(6)*(-theta2*(1-u(1))*x(2)*x(5)*phi/(x(1)+x(2)+x(3)+ x(4))^2 ...
-theta1*(1-u(1))*x(3)*x(5)*phi/(x(1)+x(2)+x(3)+x(4))^2 ...
+theta1*(1-u(1))*x(5)*phi/(x(1)+x(2)+x(3)+x(4))));
If the formula is different, please review and ensure that all parentheses are correctly balanced.
I hope this helped resolve your errors!
