I want to know where is the error please
% Symbolic
syms x(t) y(t) z(t) p k a1 a2 b2 c d sigma beta
Eqn1 = diff(x(t), t) == p*x*(1-y/k)-a1*x*y;
Eqn2 = diff(y(t), t) == c*a1*x*y-d*y-a2*y*z/(y+a2);
Eqn3 = diff(z(t), t) == sigma*z^2-beta*z^2/(y+b2);
Sols = dsolve([Eqn1, Eqn2, Eqn3])
Warning: Unable to find symbolic solution.
S= dsolve([Eqn1, Eqn2, Eqn3])
Sols
[xSol(t),ySol(t),zSol(t)] = dsolve(Eqns)
(2) Numerical Solution - see DOC:
%% Numerical solutions
ICs = [pi; pi/2; 2]; % Initial Conditions
[time, Sol]=ode45(@(t, xyz)FCN(t, xyz), [0, 10], ICs);
plot(time, Sol(:,1), 'r',time, Sol(:,2), 'g', time, Sol(:,3), 'b', 'linewidth', 2)
legend('x(t)', 'y(t)', 'z(t)'); grid on
title('Numerical Solutions')
xlabel('$t$', 'interpreter', 'latex')
ylabel('$x(t), \ y(t), \ z(t)$', 'interpreter', 'latex')
function dxyz = FCN(t, xyz)
p =.1;
k =.2;
a1 =.3;
a2 =.4;
b2 =.5;
c =.6;
d =.7;
sigma =.8;
beta =.9;
dxyz=[p*xyz(1)*(1-xyz(2)/k)-a1*xyz(1).*xyz(2);
c*a1*xyz(1).*xyz(2)-d*xyz(2)-a2*xyz(2).*xyz(3)./(xyz(2)+a2);
sigma*xyz(3).^2-(beta*xyz(3).^2)./(xyz(2)+b2)];
end
Unrecognized function or variable 'There'.
>>

 採用された回答

Star Strider
Star Strider 2022 年 12 月 30 日

0 投票

The system is nonlinear, and not one of the few nonlinear systems that haave analytic solutions.
After commenting-out the dsolve call, it appears to provide a solution —
% Symbolic
syms x(t) y(t) z(t) p k a1 a2 b2 c d sigma beta
Eqn1 = diff(x(t), t) == p*x*(1-y/k)-a1*x*y;
Eqn2 = diff(y(t), t) == c*a1*x*y-d*y-a2*y*z/(y+a2);
Eqn3 = diff(z(t), t) == sigma*z^2-beta*z^2/(y+b2);
Sols = dsolve([Eqn1, Eqn2, Eqn3])
Warning: Unable to find symbolic solution.
Sols = [ empty sym ]
% Warning: Unable to find symbolic solution.
S= dsolve([Eqn1, Eqn2, Eqn3])
Warning: Unable to find symbolic solution.
S = [ empty sym ]
Sols
Sols = [ empty sym ]
% [xSol(t),ySol(t),zSol(t)] = dsolve(Eqns)
% (2) Numerical Solution - see DOC:
%% Numerical solutions
ICs = [pi; pi/2; 2]; % Initial Conditions
[time, Sol]=ode45(@(t, xyz)FCN(t, xyz), [0, 10], ICs);
plot(time, Sol(:,1), 'r',time, Sol(:,2), 'g', time, Sol(:,3), 'b', 'linewidth', 2)
legend('x(t)', 'y(t)', 'z(t)'); grid on
title('Numerical Solutions')
xlabel('$t$', 'interpreter', 'latex')
ylabel('$x(t), \ y(t), \ z(t)$', 'interpreter', 'latex')
function dxyz = FCN(t, xyz)
p =.1;
k =.2;
a1 =.3;
a2 =.4;
b2 =.5;
c =.6;
d =.7;
sigma =.8;
beta =.9;
dxyz=[p*xyz(1)*(1-xyz(2)/k)-a1*xyz(1).*xyz(2);
c*a1*xyz(1).*xyz(2)-d*xyz(2)-a2*xyz(2).*xyz(3)./(xyz(2)+a2);
sigma*xyz(3).^2-(beta*xyz(3).^2)./(xyz(2)+b2)];
end
.

12 件のコメント

Ahmad
Ahmad 2022 年 12 月 30 日
編集済み: Ahmad 2022 年 12 月 30 日
Thank you so much
may i ask if i want to graph every equation alone with t time, what i have to put command?
Star Strider
Star Strider 2022 年 12 月 30 日
Each plot would have to go in a separate figure, or in a different subplot.
Example —
ICs = [pi; pi/2; 2]; % Initial Conditions
[time, Sol]=ode45(@(t, xyz)FCN(t, xyz), [0, 10], ICs);
ttlc = {'x(t)', 'y(t)', 'z(t)'};
cv = 'rgb';
NrSp = size(Sol,2);
for k = 1:NrSp
subplot(NrSp,1,k)
plot(time, Sol(:,k), cv(k), 'linewidth', 2)
grid on
ylim([0 3.5])
title(sprintf('Numerical Solutions: %s',ttlc{k}))
xlabel('$t$', 'interpreter', 'latex')
ylabel(sprintf('$%s$',ttlc{k}), 'interpreter', 'latex')
end
function dxyz = FCN(t, xyz)
p =.1;
k =.2;
a1 =.3;
a2 =.4;
b2 =.5;
c =.6;
d =.7;
sigma =.8;
beta =.9;
dxyz=[p*xyz(1)*(1-xyz(2)/k)-a1*xyz(1).*xyz(2);
c*a1*xyz(1).*xyz(2)-d*xyz(2)-a2*xyz(2).*xyz(3)./(xyz(2)+a2);
sigma*xyz(3).^2-(beta*xyz(3).^2)./(xyz(2)+b2)];
end
Make appropriate changes to get the result you want.
.
Ahmad
Ahmad 2022 年 12 月 30 日
I don't know why it kept give me error although i copy and paste only, i don't change anything
Star Strider
Star Strider 2022 年 12 月 30 日
Apparently, you still have the symbolic code in your script. It would be best to delete it, because there is no symbolic solution to most nonlinear differential equations, and yours are among those that do not have symbolic solutions.
Your code works if you only use the code in my previous Comment.
Ahmad
Ahmad 2022 年 12 月 30 日
編集済み: Ahmad 2022 年 12 月 30 日
okay thank you so much, i have been tried but doesn't work .and i approciate your helping, thank you again
Les Beckham
Les Beckham 2022 年 12 月 30 日
You can't paste the code into the command window. It has to be in a file. In your original question it looks like you pasted code into the command window (note the >> prompt).
Open a new script in the editor. Paste the code into the editor (you can copy it by clicking the Copy button in the upper right of Star Strider's comment above) and save it as, for example, simFCN.m.
Then you can run it from the command line as follows:
>> simFCN
Or click the Run button in the editor.
Star Strider
Star Strider 2022 年 12 月 31 日
@Les Beckham — I agree. I saw this a few hours ago. I can’t add anything to your comment.
Ahmad
Ahmad 2022 年 12 月 31 日
Thank you so much @Les Beckham and @Star Strider, I really don't have any expriance with Matlab, although I woud like to learn it , anyhow i will keep trying learning it, thank you both of you for helping me .
Star Strider
Star Strider 2022 年 12 月 31 日
As always, our pleasure!
A very good way to learn is to read the threads on MATLAB Answers, as your time permits. I have learned much from reading how other people solve problems.
.
Les Beckham
Les Beckham 2022 年 12 月 31 日
You are quite welcome.
I agree with Star Strider. Also, I would suggest taking some time to go through the online tutorial here:
Ahmad
Ahmad 2022 年 12 月 31 日
Happy new year to you, i hope that both of you will have a great 2023 and being happy with full of peaceful to both of you. also we wish that peace spread over all the worlds.
Star Strider
Star Strider 2022 年 12 月 31 日
Thank you!
And to you (and the world) as well!

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2022 年 12 月 30 日

コメント済み:

2022 年 12 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by