Problem with matlab functions
显示 更早的评论
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!