Error with Invalid indexing in system of differential equations
Show older comments
I want to solve an ODE and getting this error message:
Error using sym/subsindex (line 953)
Invalid indexing or function definition. Indexing must follow MATLAB indexing.
Function arguments must be symbolic variables, and function body must be sym
expression.
Error in kinetik_3 (line 28)
[sSol(t),eSol(t),cSol(t),pSol(t)] = dsolve(odes);
k1 = 1.0;
k2 = 0.8;
k3 = 1.1;
syms s(t) e(t) c(t) p(t)
ode1 = diff(s) == -k1*s*e + k2*c;
ode2 = diff(e) == -k1*s*e + k2*c + k3*c;
ode3 = diff(c) == k1*s*e - k2*c - k3*c;
ode4 = diff(p) == k3*c;
odes = [ode1; ode2; ode3; ode4];
cond1 = s(0) == 2.9;
cond2 = e(0) == 1.3;
cond3 = c(0) == 0;
cond4 = p(0) == 0;
conds = [cond1; cond2; cond3; cond4];
[sSol(t),eSol(t),cSol(t),pSol(t)] = dsolve(odes,conds);
Can someone please explain?
Accepted Answer
More Answers (1)
Davide Masiello
on 1 Mar 2022
I think the problem is in the syntax of your last line.
You should simply write
sSol = dsolve(odes,conds);
I run this on MatLab online and it does not throw an error any longer.
But it still cannot find a symbolic solution.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
