I need to solve this system ... I'm having problems ... I appreciate if I can help ..
syms x1(t) x2(t) y(t) E(t) O(t) t Y s(y) h(E) p(E) p q v
Dx1 = diff(x1);
Dx2 = diff(x2);
Dy = diff(y);
DE = diff(E);
DO = diff(O);
n = 0.5;
q1=0.0002;
q2=0.0001;
c1 = 0.4;
c2 = 0.3;
r1 = 0.005;
r2 = 0.006;
r3 = 0.008;
%Q(E) = 0.04;
c = 1;
d1 = 0.5;
l = 0.0234;
m = 0.04;
%equation1 = Dx1 == x1*g1(x1)-q1*x1*x2-(y*p1(x1)+r1*O*x1)*(1/(1+n*sin((2*pi*t)/365)));
equation1 = Dx1 == x1*((1000-x1)/2000)-q1*x1*x2-(y*(x1/(x1+800))+r1*O*x1)*(1/(1+n*sin((2*pi*t)/365)));
equation2 = Dx2 == x2*((900-x1)/1800)-q2*x1*x2-(y*(x2/(x2+750))+r2*O*x2)*(1/(1+n*sin((2*pi*t)/365)));
equation3 = Dy == -s(y)*y+y* (c1*(x1/(x1+800))+c1*(x1/(x1+800))-r3*O)*(1/(1+n*sin((2*pi*t)/365)));
equation4 = DE == -E*h(E)+0.04;
%equation5 = DO == -d1*O+p(E);
%g1(x1)=(1000-x1)/2000;
%g2(x2)=(900-x1)/1800;
%p1(x1)=x1/(x1+800);
%p1(x2)=x1/(x1+800);
%p2(x2)=x2/(x2+750);
%s(y)=p*(q+y/v);
[VF,Sbs] = odeToVectorField(equation1, equation2, equation3, equation4, equation5)
odefcn = matlabFunction(VF, 'Vars',{x1,x2,y})
tv = linspace(0,30, 31);
ics = [81.8/132.8, -0.0255/83, 0.625, -0.255/16.6];
[T,Y] = ode45(odefcn, tv, ics);
figure
plot(T, Y)
grid
lgdstr = sprintfc('%s', Sbs);
legend(lgdstr, 'Location','W')
title('Graf1');
xlabel('Time [days]');
ylabel('graf2')

 Accepted Answer

I managed to get it to run, however, ‘q’ and ‘v’ are nowhere defined, and need to be.
The corrected code:
syms x1(t) x2(t) y(t) E(t) O(t) t Y s(z) h(z) p(z) z q v g1(x1) g2(x2) p1(x1) p2(x2) s(y)
Dx1 = diff(x1);
Dx2 = diff(x2);
Dy = diff(y);
DE = diff(E);
DO = diff(O);
n = 0.5;
q1=0.0002;
q2=0.0001;
c1 = 0.4;
c2 = 0.3;
r1 = 0.005;
r2 = 0.006;
r3 = 0.008;
%Q(E) = 0.04;
c = 1;
d1 = 0.5;
l = 0.0234;
m = 0.04;
p(z) = l+m*z;
s(z)=p(q+z/v);
h(z) = c;
%equation1 = Dx1 == x1*g1(x1)-q1*x1*x2-(y*p1(x1)+r1*O*x1)*(1/(1+n*sin((2*pi*t)/365)));
equation1 = Dx1 == x1*((1000-x1)/2000)-q1*x1*x2-(y*(x1/(x1+800))+r1*O*x1)*(1/(1+n*sin((2*pi*t)/365)));
equation2 = Dx2 == x2*((900-x1)/1800)-q2*x1*x2-(y*(x2/(x2+750))+r2*O*x2)*(1/(1+n*sin((2*pi*t)/365)));
equation3 = Dy == -s(y)*y+y* (c1*(x1/(x1+800))+c1*(x1/(x1+800))-r3*O)*(1/(1+n*sin((2*pi*t)/365)));
equation4 = DE == -E*h(E)+0.04;
equation5 = DO == -d1*O+p(E);
%g1(x1)=(1000-x1)/2000;
%g2(x2)=(900-x1)/1800;
%p1(x1)=x1/(x1+800);
%p1(x2)=x1/(x1+800);
%p2(x2)=x2/(x2+750);
%s(y)=p*(q+y/v);
[VF,Sbs] = odeToVectorField(equation1, equation2, equation3, equation4, equation5)
odefcn = matlabFunction(VF, 'Vars',{t,Y,q,v})
tv = linspace(0,30, 31);
ics = [81.8/132.8, -0.0255/83, 0.625, -0.255/16.6, rand];
q = rand;
v = rand;
[T,Y] = ode45(@(t,Y)odefcn(t,Y,q,v), tv, ics);
figure
sbp = size(Y,2);
lgdstr = sprintfc('%s', Sbs);
for k = 1:sbp
subplot(sbp,1,k)
plot(T, Y(:,k), 'LineWidth',1.5)
grid
title(lgdstr{k})
end
% lgdstr = sprintfc('%s', Sbs);
% legend(lgdstr, 'Location','W')
sgtitle('Graf1');
xlabel('Time [days]');
ylabel('graf2')
producing:
odefcn = @(t,Y,q,v)[-(Y(1).*Y(5).*(3.0./5.0e+2)+(Y(1).*Y(3))./(Y(1)+7.5e+2))./(sin(t.*pi.*(2.0./3.65e+2))./2.0+1.0)-(Y(2)./1.8e+3-1.0./2.0).*Y(1)-(Y(1).*Y(2))./1.0e+4;-((Y(2).*Y(5))./2.0e+2+(Y(2).*Y(3))./(Y(2)+8.0e+2))./(sin(t.*pi.*(2.0./3.65e+2))./2.0+1.0)-(Y(2)./2.0e+3-1.0./2.0).*Y(2)-(Y(1).*Y(2))./5.0e+3;-Y(3).*(q./2.5e+1+Y(3)./(v.*2.5e+1)+2.34e-2)+(((Y(2).*(4.0./5.0))./(Y(2)+8.0e+2)-Y(5)./1.25e+2).*Y(3))./(sin(t.*pi.*(2.0./3.65e+2))./2.0+1.0);-Y(4)+1.0./2.5e+1;Y(4)./2.5e+1-Y(5)./2.0+2.34e-2];
I filled in the unknown parameters and initial conditions with rand calls, so I did not post the plot. You will need to provide the correct values. I intorduced ‘z’ as an argument to functions that are not derivatives, because the Symbolic Math Toolbox did not accept them as otherwise written. It does not actually matter, because they will evaluate correctly with the correct arguments. I used a subplot loop because ‘x1’ otherwise dominates the plot, and the others are essentially invisible, all being bounded by ±1. Make any necessary changes, in the event that my approach to get it to run turns out not to provide the correct result.
.

More Answers (0)

Categories

Find more on Mathematics 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!