where is the error
显示 更早的评论
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'.
>> 

采纳的回答
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 个评论
Thank you so much
may i ask if i want to graph every equation alone with t time, what i have to put command?
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.
.

I don't know why it kept give me error although i copy and paste only, i don't change anything
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.
okay thank you so much, i have been tried but doesn't work .and i approciate your helping, thank you again
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.
@Les Beckham — I agree. I saw this a few hours ago. I can’t add anything to your comment.
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 .
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.
.
You are quite welcome.
I agree with Star Strider. Also, I would suggest taking some time to go through the online tutorial here:
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.
Thank you!
And to you (and the world) as well!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Solvers 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
