Problem with matlab functions
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all!!
I have a problem with matlab...
I'm trying to solve a ode but before getting to it i'm having trouble defining the function first. The code is the following:
function dXdt = third_simplified_model(~,C)
clc
load Gmatrix;
load Xmatrix;
global k1 k24 k34 k41
i = 750;
if i == 700 const = Gmatrix(:,2); conv = Xmatrix(:,1); elseif i == 750 const = Gmatrix(:,3); conv = Xmatrix(:,2); elseif i == 800 const = Gmatrix(:,4); conv = Xmatrix(:,3); end
const0 = Gmatrix(:,1);
% construction of the function
dXdt = zeros(4,1);
dXdt(1) = k41*C(4) - k1*C(1) - const0(1);
dXdt(2) = - k24*C(2) - const0(2);
dXdt(3) = - k34*C(3) - const0(3);
dXdt(4) = k24*C(2) + k34*C(3) - k41*C(4) - const0(4);
for k1 = 0.1:0.01:50
for k24 = 0.1:0.01:10
for k34 = 0.1:0.01:10
for k41 = 0.1:0.01:50
sol = ode45(@third_simplified_model,tspan,[const(1) const(2) const(3) const(4)]);
end
end
end
end
end
When it comes to the definition of dXdt (1) it gives this error:
??? Input argument "C" is undefined.
Error in ==> third_simplified_model at 35 dXdt(1) = k41*C(4) - k1*C(1) - const0(1);
I've tried several things but nothing works... I don't know if it is from my programming or if it is from the matlab itself because I also tried with the example that the tutorials give to this type of ode solver and it gives exactly the same error:
function dy = rigid(~,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
[T,Y] = ode45(@rigid,[0 12],[0 1 1]);
??? Input argument "y" is undefined.
Error in ==> rigid at 4 dy(1) = y(2) * y(3);
Any suggestions?
Thanks!! =D
0 Commenti
Risposta accettata
Arnaud Miege
il 5 Apr 2011
Make sure your function code is saved in a separate file, third_simplified_model.m. You may want to add an end statement at the end of the file (after the line dXdt(4) = k24*C(2) + k34*C(3) - k41*C(4) - const0(4);).
Then in the MATLAB command window, or in a separate script, run the commands to solve the ODE:
for k1 = 0.1:0.01:50
for k24 = 0.1:0.01:10
for k34 = 0.1:0.01:10
for k41 = 0.1:0.01:50
sol = ode45(@third_simplified_model,tspan,[const(1) const(2) const(3) const(4)]);
end
end
end
end
I have tried it with the rigid example and it works.
Note that with your code as is, you are overwriting the value of the variable sol at each iteration.
HTH,
Arnaud
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!