I need to find the general solution of multiple x functions from stiff differential equations. I am using ode45 however my code is not plotting the graphs as it is giving me the "Error updating FunctionLine" warning, I am unsure how to fix this issue, as this is my first time using ode45. Please let me know where is it causing a issue and how i can overcome it.
cons = [con1,con2,con3];
tspan = [0 5];
[t,x] = ode45(@(t,x)odefcn(t,x1,x2,x3), tspan, cons);
fplot(x1,[0,5],'color','c')
hold on
fplot(x2,[0,5],'color','m')
hold on
fplot(x3,[0,5],'color','k')
xlabel('time/(t)')
ylabel('Amount of water/x(t)')
legend({'x1(t)','x2(t)','x3(t)'},'Location','southeast')
function dxdt = odefcn(t,x1,x2,x3)
dxdt = zeros(3,1);
dx1 = 1/3*x3(t) - 1/2*x1(t);
dx2 = 1/2*x1(t) - 1/2*x2(t);
dx3 = 1/2*x2(t) - 1/3*x3(t);
end

 采纳的回答

Torsten
Torsten 2022-3-21
编辑:Torsten 2022-3-21
cons = [con1,con2,con3];
tspan = [0 5];
[t,x] = ode45(@(t,x)odefcn(t,x(1),x(2),x(3)), tspan, cons);
plot(t,x(:,1),'color','c')
hold on
plot(t,x(:,2),'color','m')
hold on
plot(t,x(:,3),'color','k')
xlabel('time/(t)')
ylabel('Amount of water/x(t)')
legend({'x1(t)','x2(t)','x3(t)'},'Location','southeast')
function dxdt = odefcn(t,x1,x2,x3)
dxdt = zeros(3,1);
dx1 = 1/3*x3 - 1/2*x1;
dx2 = 1/2*x1 - 1/2*x2;
dx2 = 1/2*x2 - 1/3*x3;
dxdt = [dx1;dx2;dx3];
end

更多回答(0 个)

类别

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by