How to use for loop when have syms inside the loop
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello guys,
I want to ask about, how to use for loop when I have syms and diff inside looping. Here is my code that I tried to solve. Thank you
Xmax = 1410.34;
conc = [50 100 150]*1e-9;
ka = 3.46e3;
kd = 1.46e-4;
for i = 1:length(conc)
syms t x(t)
eqn = diff(x,t) == (ka*conc(:,i)*Xmax)-(ka*conc(:,i))*x-kd*x;
cond = x(0) == 0;
X_ass(t) = dsolve(eqn,cond);
X_ass = matlabFunction(X_ass);
t = linspace(0, 1800, 600)';
signal(:,i) = [X_ass(t)];
end
When I used this code, MATLAB give me warning this:
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function
body must be sym expression.
0 Commenti
Risposte (1)
Torsten
il 30 Mag 2022
Try
syms t x(t)
Xmax = 1410.34;
conc = [50 100 150]*1e-9;
ka = 3.46e3;
kd = 1.46e-4;
for i = 1:length(conc)
eqn = diff(x,t) == (ka*conc(1,i)*Xmax)-(ka*conc(1,i))*x-kd*x;
cond = x(0) == 0;
X_ass(t) = dsolve(eqn,cond);
X_ass = matlabFunction(X_ass);
T = linspace(0, 1800, 600)';
signal(:,i) = X_ass(T);
end
2 Commenti
Torsten
il 31 Mag 2022
Try
syms t x(t) c
Xmax = 1410.34;
conc = [50 100 150]*1e-9;
ka = 3.46e3;
kd = 1.46e-4;
T = linspace(0, 1800, 600)';
eqn = diff(x,t) == (ka*c*Xmax)-(ka*c)*x-kd*x;
cond = x(0)==0;
X_ass(t) = dsolve(eqn,cond);
for i = 1:numel(conc)
X_ass_fun = matlabFunction(subs(X_ass,c,conc(i)));
signal(:,i) = X_ass_fun(T);
end
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!